use of abs.frontend.typechecker.TypeParameter in project abstools by abstools.
the class TypingTest method functionTypeArgs5.
@Test
public void functionTypeArgs5() {
Model m = assertParseOkStdLib("def B nth<B>(List<B> list, Int n) = nth(tail(list), n-1) ; ");
ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
TypeParameterDecl typeParameter = d.getTypeParameter(0);
TypeParameter type = (TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
assertEquals(typeParameter.getName(), type.getDecl().getName());
}
use of abs.frontend.typechecker.TypeParameter in project abstools by abstools.
the class TypeExtensionHelper method checkFnApp.
public void checkFnApp(FnApp f) {
FunctionDecl decl = (FunctionDecl) f.getDecl();
if (decl instanceof ParametricFunctionDecl) {
HashMap<TypeParameter, Type> map = new HashMap<>();
for (int i = 0; i < decl.getNumParam(); i++) {
Type t = f.getParam(i).getType();
Type arg = decl.getParam(i).getType();
checkTypeParameter(map, t, arg, f.getParam(i));
}
} else {
checkAssignable(null, decl, f);
}
}
use of abs.frontend.typechecker.TypeParameter in project abstools by abstools.
the class TypeExtensionHelper method checkTypeParameter.
private void checkTypeParameter(HashMap<TypeParameter, Type> map, Type rht, Type lht, ASTNode<?> origin) {
rht = resolveBoundedType(rht);
if (rht.isBoundedType())
return;
if (lht.isTypeParameter() && rht.isReferenceType()) {
TypeParameter typeParam = (TypeParameter) lht;
Type lt = map.get(typeParam);
if (lt != null) {
checkEq(lt, rht, origin);
} else {
map.put(typeParam, rht);
}
} else if (lht.isDataType()) {
DataTypeType argdt = (DataTypeType) lht;
if (argdt.hasTypeArgs()) {
DataTypeType dt = (DataTypeType) rht;
for (int i = 0; i < dt.numTypeArgs(); i++) {
checkTypeParameter(map, dt.getTypeArg(i), argdt.getTypeArg(i), origin);
}
}
} else if (lht.isReferenceType()) {
checkEq(lht, rht, origin);
}
}
use of abs.frontend.typechecker.TypeParameter in project abstools by abstools.
the class TypingTest method functionTypeArgs.
@Test
public void functionTypeArgs() {
Model m = assertParseOkStdLib(" def Maybe<A> f<A>() = None ;");
ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
DataTypeType t = (DataTypeType) d.getTypeUse().getType();
TypeParameter typeArg = (TypeParameter) t.getTypeArg(0);
assertEquals(typeArg.getDecl(), d.getTypeParameter(0));
}
use of abs.frontend.typechecker.TypeParameter in project abstools by abstools.
the class TypingTest method functionTypeArgs3.
@Test
public void functionTypeArgs3() {
Model m = assertParseOkStdLib(" def A f<A>(Maybe<A> o) = case o { Just(a) => a; } ;");
ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
TypeParameterDecl typeParameter = d.getTypeParameter(0);
TypeParameter type = (TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
TypeParameterDecl decl = type.getDecl();
assertEquals(typeParameter, decl);
}
Aggregations