X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fcompilation%2FTypeChecking.java;h=ff713b1705a85284c841e1fb2a9393aa0a3a4d19;hb=976bf85e9915e294d39d2673d7f8bb90f6a70144;hp=667c089c3e24fe58561a674622f053a0ed6d9662;hpb=a8758de5bc19e5adb3f618d3038743a164f09912;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java index 667c089c3..ff713b170 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java @@ -186,6 +186,7 @@ public class TypeChecking { .closure(vars)); value.setType(Types.forAll(vars, Types.constrained(constraints, value.getType()))); + //System.out.println(value.getName() + " :: " + value.getType()); // Add evidence parameters to recursive calls for(EPlaceholder ref : recursiveReferences) { @@ -204,6 +205,9 @@ public class TypeChecking { Expression expression = value.getExpression(); + int errorCountBeforeTypeChecking = compilationContext.errorLog.getErrorCount(); + int functionArity = expression.getSyntacticFunctionArity(); + try { ArrayList vars = new ArrayList(); type = Types.removeForAll(type, vars); @@ -217,7 +221,15 @@ public class TypeChecking { for(EAmbiguous overloaded : context.overloadedExpressions) overloaded.assertResolved(compilationContext.errorLog); expression.getType().addPolarity(Polarity.POSITIVE); + //System.out.println("--- " + value.getName() + " -------------------------------------------------------------------------"); context.solveSubsumptions(expression.getLocation()); + + if(compilationContext.errorLog.getErrorCount() != errorCountBeforeTypeChecking) { + int typeArity = Types.getArity(type); + if(typeArity != functionArity) + compilationContext.errorLog.logWarning(value.definitionLocation, "Possible problem: type declaration has " + typeArity + " parameter types, but function definition has " + functionArity + " parameters."); + } + ArrayList demands = context.getConstraintDemand(); if(!demands.isEmpty() || !givenConstraints.isEmpty()) { ReducedConstraints red = @@ -227,7 +239,7 @@ public class TypeChecking { compilationContext.errorLog.log(c.getDemandLocation(), "Constraint <"+c.constraint+"> is not given and cannot be derived."); } - if(compilationContext.errorLog.isEmpty()) { // To prevent exceptions + if(compilationContext.errorLog.hasNoErrors()) { // To prevent exceptions expression = ExpressionAugmentation.augmentSolved( red.solvedConstraints, expression); @@ -237,7 +249,7 @@ public class TypeChecking { } } else { - if(compilationContext.errorLog.isEmpty()) // To prevent exceptions + if(compilationContext.errorLog.hasNoErrors()) // To prevent exceptions expression = expression.decomposeMatching(); } expression = expression.closure(vars.toArray(new TVar[vars.size()])); @@ -333,7 +345,7 @@ public class TypeChecking { } public void typeCheck() { - ce = new ConstraintEnvironment(environment); + ce = new ConstraintEnvironment(compilationContext); scheduler = new TypeCheckingScheduler(compilationContext); typeCheckValues(); @@ -398,7 +410,7 @@ public class TypeChecking { for(TransformationRule rule : module.getRules()) for(Query[] queries : rule.sections.values()) for(Query query : queries) - query.collectRefs(allRefs, refs); + query.collectRefs(allRefs, refs); } @Override