From: Hannu Niemistö Date: Thu, 12 Apr 2018 07:04:44 +0000 (+0300) Subject: (refs #7866) Better error location for the NPE in compilation X-Git-Tag: v1.43.0~136^2~497^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=21eae91e860f9f3cdb9cd0ee6fded24cdb8ca2f5;p=simantics%2Fplatform.git (refs #7866) Better error location for the NPE in compilation Change-Id: I3027ac4cd1061edefed6b46ddf1c79773d03caca --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/exceptions/InternalCompilerError.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/exceptions/InternalCompilerError.java index 71b619301..1c2709665 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/exceptions/InternalCompilerError.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/exceptions/InternalCompilerError.java @@ -36,5 +36,16 @@ public class InternalCompilerError extends RuntimeException { super(cause); this.location = location; } + + public static InternalCompilerError injectLocation(long location, Throwable cause) { + if(cause instanceof InternalCompilerError) { + InternalCompilerError e = (InternalCompilerError)cause; + if(e.location == Locations.NO_LOCATION) + e.location = location; + return e; + } + else + return new InternalCompilerError(location, cause); + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java index 2d97ab518..7bee6eae0 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java @@ -1,5 +1,6 @@ package org.simantics.scl.compiler.elaboration.chr; +import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; import org.simantics.scl.compiler.elaboration.chr.plan.PostCommitOp; import org.simantics.scl.compiler.elaboration.chr.plan.PreCommitOp; import org.simantics.scl.compiler.elaboration.chr.planning.QueryPlanningContext; @@ -20,8 +21,9 @@ import gnu.trove.set.hash.TIntHashSet; public class CHRQuery extends Symbol { public CHRLiteral[] literals; - public CHRQuery(CHRLiteral[] literals) { + public CHRQuery(long location, CHRLiteral[] literals) { this.literals = literals; + this.location = location; } public void resolve(TranslationContext context) { @@ -48,17 +50,21 @@ public class CHRQuery extends Symbol { } public boolean createQueryPlan(QueryPlanningContext context, Expression inputFact, int activeLiteralId, CHRConstraint initConstraint) { - for(int i=0;i literals = new ArrayList(); translate(context, mode, literals); - return new CHRQuery(literals.toArray(new CHRLiteral[literals.size()])); + return new CHRQuery(location, literals.toArray(new CHRLiteral[literals.size()])); } protected abstract void translate(TranslationContext context, CHRQueryTranslationMode mode, ArrayList literals); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/translation/CHRTranslation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/translation/CHRTranslation.java index 260927b74..107905ae3 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/translation/CHRTranslation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/translation/CHRTranslation.java @@ -129,13 +129,15 @@ public class CHRTranslation { } public static CHRQuery convertCHRQuery(TranslationContext context, boolean isHead, ListQualifier[] lqs) { + long location = Locations.NO_LOCATION; ArrayList query = new ArrayList(lqs.length); for(ListQualifier qualifier : lqs) { + location = Locations.combine(location, qualifier.location); CHRLiteral literal = convertListQualifier(context, isHead, qualifier); if(literal != null) query.add(literal); } - return new CHRQuery(query.toArray(new CHRLiteral[query.size()])); + return new CHRQuery(location, query.toArray(new CHRLiteral[query.size()])); } /*public static CHRRule convertCHRStatement(TranslationContext context, CHRStatement statement) { diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java index 7b693aa62..3eb098933 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java @@ -1,5 +1,6 @@ package org.simantics.scl.compiler.tests; +import org.junit.Ignore; import org.junit.Test; import org.simantics.scl.compiler.top.ValueNotFound; @@ -36,6 +37,7 @@ public class ModuleRegressionTests extends TestBase { @Test public void CHR11() { test(); } @Test public void CHR12() { test(); } @Test public void CHR13() { test(); } + @Ignore @Test public void CHR14() { test(); } @Test public void CHRSelect1() { test(); } @Test public void CHRSelect2() { test(); } @Test public void CHRSelect3() { test(); } diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR14.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR14.scl new file mode 100644 index 000000000..f9f17796e --- /dev/null +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/CHR14.scl @@ -0,0 +1,16 @@ +module { export = [main], features = [chr] } +import "Prelude" + +ruleset A where + constraint AR Integer Integer + +pcombine :: A -> () +pcombine a = () + where + include A a + + -AR ?a ?b => True + +main = () +-- +() \ No newline at end of file