Skip to content

Commit 8f8ab04

Browse files
committed
Fix enum constants
1 parent 186c2af commit 8f8ab04

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

tern-compile/src/test/java/org/ternlang/compile/staticanalysis/InvalidGenericCountTest.java

-14
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.ternlang.compile.staticanalysis;
2+
3+
public class InvalidGenericsTest extends CompileTestCase {
4+
5+
private static final String FAILURE_1 =
6+
"class Foo<T>{\n"+
7+
" dump(a): T {}\n"+
8+
"}\n"+
9+
"new Foo<Double>().dump(11).size();\n";
10+
11+
private static final String FAILURE_2 =
12+
"class Foo<T>{\n"+
13+
" dump(a): T {}\n"+
14+
"}\n"+
15+
"Foo<Double>().dump(11).size();\n";
16+
17+
private static final String FAILURE_3 =
18+
"func fun<A, B>(a: A): List<B> {\n"+
19+
" return null;\n"+
20+
"}\n"+
21+
"fun<Double, Double, Double>(1.0).intValue();\n";
22+
23+
public void testGenericFunction() throws Exception {
24+
assertCompileError(FAILURE_1, "Function 'size()' not found for 'lang.Double' in /default.tern at line 4");
25+
assertCompileError(FAILURE_2, "Function 'size()' not found for 'lang.Double' in /default.tern at line 4");
26+
assertCompileError(FAILURE_3, "Generic parameter count for 'default.fun(a: Object)' is invalid in /default.tern at line 4");
27+
28+
}
29+
}

tern-core/src/main/java/org/ternlang/core/constraint/StaticConstraint.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.ternlang.core.constraint;
22

3+
import static java.util.Collections.EMPTY_LIST;
4+
5+
import java.util.List;
6+
37
import org.ternlang.core.ModifierType;
48
import org.ternlang.core.scope.Scope;
59
import org.ternlang.core.type.Type;
@@ -20,11 +24,16 @@ public StaticConstraint(Type type, int modifiers) {
2024
this.type = type;
2125
}
2226

27+
@Override
28+
public List<Constraint> getGenerics(Scope scope) {
29+
return type.getGenerics();
30+
}
31+
2332
@Override
2433
public Type getType(Scope scope) {
2534
return type;
2635
}
27-
36+
2837
@Override
2938
public boolean isVariable(){
3039
return !ModifierType.isConstant(modifiers);

tern-core/src/main/java/org/ternlang/core/type/index/PropertyGenerator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public PropertyGenerator(){
2424
super();
2525
}
2626

27-
public Property generate(Type type, Constraint constraint, String name, int modifiers) {
27+
public Property generate(Type type, Constraint constraint, Object value, String name, int modifiers) {
2828
try {
29-
return new ConstantProperty(name, type, constraint, type, modifiers);
29+
return new ConstantProperty(name, type, constraint, value, modifiers);
3030
} catch(Exception e) {
3131
throw new InternalStateException("Could not create property from " + type);
3232
}

tern-core/src/main/java/org/ternlang/core/type/index/PropertyIndexer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private List<Property> index(Type type, Class[] types) throws Exception {
113113
String name = entry.getSimpleName();
114114
Type element = indexer.loadType(entry);
115115
Constraint constraint = Constraint.getConstraint(element, CLASS.mask);
116-
Property property = generator.generate(element, constraint, name, modifiers | CONSTANT.mask);
116+
Property property = generator.generate(type, constraint, element, name, modifiers | CONSTANT.mask);
117117
List<Annotation> extracted = extractor.extract(entry);
118118
List<Annotation> actual = property.getAnnotations();
119119

0 commit comments

Comments
 (0)