diff --git a/tern-compile/src/test/java/org/ternlang/compile/staticanalysis/InvalidGenericCountTest.java b/tern-compile/src/test/java/org/ternlang/compile/staticanalysis/InvalidGenericCountTest.java deleted file mode 100644 index a29123db..00000000 --- a/tern-compile/src/test/java/org/ternlang/compile/staticanalysis/InvalidGenericCountTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.ternlang.compile.staticanalysis; - -public class InvalidGenericCountTest extends CompileTestCase { - - private static final String FAILURE_1 = - "func fun(a: A): B {\n"+ - " return null;\n"+ - "}\n"+ - "fun(1.0).intValue();\n"; - - public void testGenericFunction() throws Exception { - assertCompileError(FAILURE_1, "Generic parameter count for 'default.fun(a: Object)' is invalid in /default.tern at line 4"); - } -} diff --git a/tern-compile/src/test/java/org/ternlang/compile/staticanalysis/InvalidGenericsTest.java b/tern-compile/src/test/java/org/ternlang/compile/staticanalysis/InvalidGenericsTest.java new file mode 100644 index 00000000..5f965916 --- /dev/null +++ b/tern-compile/src/test/java/org/ternlang/compile/staticanalysis/InvalidGenericsTest.java @@ -0,0 +1,29 @@ +package org.ternlang.compile.staticanalysis; + +public class InvalidGenericsTest extends CompileTestCase { + + private static final String FAILURE_1 = + "class Foo{\n"+ + " dump(a): T {}\n"+ + "}\n"+ + "new Foo().dump(11).size();\n"; + + private static final String FAILURE_2 = + "class Foo{\n"+ + " dump(a): T {}\n"+ + "}\n"+ + "Foo().dump(11).size();\n"; + + private static final String FAILURE_3 = + "func fun(a: A): List {\n"+ + " return null;\n"+ + "}\n"+ + "fun(1.0).intValue();\n"; + + public void testGenericFunction() throws Exception { + assertCompileError(FAILURE_1, "Function 'size()' not found for 'lang.Double' in /default.tern at line 4"); + assertCompileError(FAILURE_2, "Function 'size()' not found for 'lang.Double' in /default.tern at line 4"); + assertCompileError(FAILURE_3, "Generic parameter count for 'default.fun(a: Object)' is invalid in /default.tern at line 4"); + + } +} diff --git a/tern-core/src/main/java/org/ternlang/core/constraint/StaticConstraint.java b/tern-core/src/main/java/org/ternlang/core/constraint/StaticConstraint.java index c54a2d93..1ee1822e 100644 --- a/tern-core/src/main/java/org/ternlang/core/constraint/StaticConstraint.java +++ b/tern-core/src/main/java/org/ternlang/core/constraint/StaticConstraint.java @@ -1,5 +1,9 @@ package org.ternlang.core.constraint; +import static java.util.Collections.EMPTY_LIST; + +import java.util.List; + import org.ternlang.core.ModifierType; import org.ternlang.core.scope.Scope; import org.ternlang.core.type.Type; @@ -20,11 +24,16 @@ public StaticConstraint(Type type, int modifiers) { this.type = type; } + @Override + public List getGenerics(Scope scope) { + return type.getGenerics(); + } + @Override public Type getType(Scope scope) { return type; } - + @Override public boolean isVariable(){ return !ModifierType.isConstant(modifiers); diff --git a/tern-core/src/main/java/org/ternlang/core/type/index/PropertyGenerator.java b/tern-core/src/main/java/org/ternlang/core/type/index/PropertyGenerator.java index 440bf31f..55b2def6 100644 --- a/tern-core/src/main/java/org/ternlang/core/type/index/PropertyGenerator.java +++ b/tern-core/src/main/java/org/ternlang/core/type/index/PropertyGenerator.java @@ -24,9 +24,9 @@ public PropertyGenerator(){ super(); } - public Property generate(Type type, Constraint constraint, String name, int modifiers) { + public Property generate(Type type, Constraint constraint, Object value, String name, int modifiers) { try { - return new ConstantProperty(name, type, constraint, type, modifiers); + return new ConstantProperty(name, type, constraint, value, modifiers); } catch(Exception e) { throw new InternalStateException("Could not create property from " + type); } diff --git a/tern-core/src/main/java/org/ternlang/core/type/index/PropertyIndexer.java b/tern-core/src/main/java/org/ternlang/core/type/index/PropertyIndexer.java index 9865caab..e6c65c8a 100644 --- a/tern-core/src/main/java/org/ternlang/core/type/index/PropertyIndexer.java +++ b/tern-core/src/main/java/org/ternlang/core/type/index/PropertyIndexer.java @@ -113,7 +113,7 @@ private List index(Type type, Class[] types) throws Exception { String name = entry.getSimpleName(); Type element = indexer.loadType(entry); Constraint constraint = Constraint.getConstraint(element, CLASS.mask); - Property property = generator.generate(element, constraint, name, modifiers | CONSTANT.mask); + Property property = generator.generate(type, constraint, element, name, modifiers | CONSTANT.mask); List extracted = extractor.extract(entry); List actual = property.getAnnotations();