Skip to content

Commit 525915b

Browse files
author
dwightguth
authored
Fix incorrect priority attribute on :/=K (runtimeverification#364)
* fix priority of ==K * test for ambiguity * fix for w2e on parsing warnings * add test for fatal ambiguity * fix display as error not warning * another typo * add regression test
1 parent 3f7666a commit 525915b

7 files changed

Lines changed: 50 additions & 5 deletions

File tree

k-distribution/include/builtin/domains.k

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,8 @@ module K-EQUAL
786786
change in the future).*/
787787

788788
syntax Bool ::= left:
789-
K ":=K" K [function, functional, klabel(_:=K_), symbol, equalsEqualsK]
790-
| K ":/=K" K [function, functional, klabel(_:/=K_), symbol, notEqualsEqualsK]
789+
K ":=K" K [function, functional, klabel(_:=K_), symbol, equalEqualK]
790+
| K ":/=K" K [function, functional, klabel(_:/=K_), symbol, notEqualEqualK]
791791

792792
syntax priorities equalEqualK notEqualEqualK > boolOperation mlOp
793793
rule K1:K =/=K K2:K => notBool (K1 ==K K2)

k-distribution/tests/regression-new/equals-pattern/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ DEF=test
22
EXT=test
33
TESTDIR=.
44
KOMPILE_BACKEND?=llvm
5+
KOMPILE_FLAGS=-w2e
56

67
include ../../../include/ktest.mak

k-distribution/tests/regression-new/equals-pattern/test.k

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Copyright (c) 2019 K Team. All Rights Reserved.
2-
module TEST
2+
3+
module TEST-SYNTAX
34
imports INT
45
imports K-EQUAL
56

6-
syntax KItem ::= foo(Int) | bar(Int) | baz(KItem)
7+
syntax KItem ::= foo(Int) | bar(Int) | baz(KItem) | stuff(K) | StringLiteral(K) | WStringLiteral(K)
78

89
rule I:Int => foo(_) :=K foo(I)
910
requires I ==Int 0
@@ -19,4 +20,14 @@ rule baz(A:KItem) => #fun(baz(B) => baz(bar(_)) :=K baz(B))(baz(A))
1920
requires baz(_) :/=K A
2021
rule baz(baz(A:KItem)) => #fun(baz(B) => baz(A) :=K baz(B))(baz(A))
2122

23+
rule stuff(K) => 1
24+
requires StringLiteral(...) :/=K K
25+
andBool WStringLiteral(...) :/=K K
26+
rule stuff(K) => 1
27+
requires StringLiteral(...) :=K K
28+
andBool WStringLiteral(...) :=K K
29+
endmodule
30+
31+
module TEST
32+
imports TEST-SYNTAX
2233
endmodule
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module TEST2-SYNTAX
2+
3+
endmodule
4+
5+
module TEST2
6+
imports TEST2-SYNTAX
7+
8+
syntax Foo ::= "foo" [klabel(foo), symbol]
9+
syntax Bar ::= "foo" [klabel(bar), symbol]
10+
11+
rule foo => 0
12+
endmodule
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Error] Compiler: Had 1 parsing errors.
2+
[Error] Inner Parser: Parsing ambiguity. Arbitrarily choosing the first.
3+
1: syntax Bar ::= "foo"
4+
bar(.KList)
5+
2: syntax Foo ::= "foo"
6+
foo(.KList)
7+
Source(test2.k)
8+
Location(11,8,11,11)

kernel/src/main/java/org/kframework/kompile/DefinitionParsing.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.kframework.utils.errorsystem.KEMException;
3232
import org.kframework.utils.errorsystem.KExceptionManager;
3333
import org.kframework.utils.errorsystem.ParseFailedException;
34+
import org.kframework.utils.errorsystem.KException.ExceptionType;
3435
import org.kframework.utils.file.FileUtil;
3536
import scala.Option;
3637
import scala.Tuple2;
@@ -392,7 +393,15 @@ private Stream<? extends K> performParse(Map<String, ParsedSentence> cache, Pars
392393
}
393394
result = parser.parseString(b.contents(), START_SYMBOL, scanner, source, startLine, startColumn, !b.att().contains("macro") && !b.att().contains("alias"));
394395
parsedBubbles.getAndIncrement();
395-
kem.addAllKException(result._2().stream().map(e -> e.getKException()).collect(Collectors.toList()));
396+
if (kem.options.warnings2errors && !result._2().isEmpty()) {
397+
for (KEMException err : result._2()) {
398+
if (kem.options.warnings.includesExceptionType(err.exception.getType())) {
399+
errors.add(KEMException.asError(err));
400+
}
401+
}
402+
} else {
403+
kem.addAllKException(result._2().stream().map(e -> e.getKException()).collect(Collectors.toList()));
404+
}
396405
if (result._1().isRight()) {
397406
KApply k = (KApply) new TreeNodesToKORE(Outer::parseSort, isStrict).down(result._1().right().get());
398407
k = KApply(k.klabel(), k.klist(), k.att().addAll(b.att().remove("contentStartLine").remove("contentStartColumn").remove(Source.class).remove(Location.class)));

kore/src/main/java/org/kframework/utils/errorsystem/KEMException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public static KEMException outerParserError(String message, Throwable e, Source
9494
return create(ExceptionType.ERROR, KExceptionGroup.OUTER_PARSER, message, e, location, source);
9595
}
9696

97+
public static KEMException asError(KEMException warning) {
98+
return new KEMException(warning.exception, ExceptionType.ERROR);
99+
}
100+
97101
@Override
98102
public String getMessage() {
99103
return exception.toString();

0 commit comments

Comments
 (0)