Skip to content

Commit

Permalink
Fix enum constants
Browse files Browse the repository at this point in the history
  • Loading branch information
ngallagher committed May 11, 2019
1 parent 186c2af commit 8f8ab04
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.ternlang.compile.staticanalysis;

public class InvalidGenericsTest extends CompileTestCase {

private static final String FAILURE_1 =
"class Foo<T>{\n"+
" dump(a): T {}\n"+
"}\n"+
"new Foo<Double>().dump(11).size();\n";

private static final String FAILURE_2 =
"class Foo<T>{\n"+
" dump(a): T {}\n"+
"}\n"+
"Foo<Double>().dump(11).size();\n";

private static final String FAILURE_3 =
"func fun<A, B>(a: A): List<B> {\n"+
" return null;\n"+
"}\n"+
"fun<Double, Double, Double>(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");

}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,11 +24,16 @@ public StaticConstraint(Type type, int modifiers) {
this.type = type;
}

@Override
public List<Constraint> getGenerics(Scope scope) {
return type.getGenerics();
}

@Override
public Type getType(Scope scope) {
return type;
}

@Override
public boolean isVariable(){
return !ModifierType.isConstant(modifiers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private List<Property> 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<Annotation> extracted = extractor.extract(entry);
List<Annotation> actual = property.getAnnotations();

Expand Down

0 comments on commit 8f8ab04

Please sign in to comment.