Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
devops committed Sep 26, 2023
2 parents 09874ad + 6bda50e commit dfc06a5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
13 changes: 13 additions & 0 deletions k-distribution/tests/regression-new/checks/expandMacroEnsures.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) K Team. All Rights Reserved.

module EXPANDMACROENSURES
imports INT
imports BOOL

syntax Int ::= #foo ( Int ) [function]
syntax Bool ::= #baz ( Int ) [alias]

// rule #baz ( X ) => X // NOTE I should be defined !!

rule #foo( X ) => X ensures #baz( X )
endmodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Error] Compiler: Rule contains macro symbol that was not expanded
Source(expandMacroEnsures.k)
Location(12,10,12,49)
12 | rule #foo( X ) => X ensures #baz( X )
. ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Error] Compiler: Had 1 structural errors after macro expansion.
while executing phase "expand macros" on sentence at
Source(expandMacroEnsures.k)
Location(12,10,12,49)
13 changes: 13 additions & 0 deletions k-distribution/tests/regression-new/checks/expandMacroRequires.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) K Team. All Rights Reserved.

module EXPANDMACROREQUIRES
imports INT
imports BOOL

syntax Int ::= #foo ( Int ) [function]
syntax Bool ::= #bar ( Int ) [alias]

// rule #bar ( X ) => X >Int 0 // NOTE I should be defined !!

rule #foo( X ) => X requires #bar( X )
endmodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Error] Compiler: Rule contains macro symbol that was not expanded
Source(expandMacroRequires.k)
Location(12,10,12,49)
12 | rule #foo( X ) => X requires #bar( X )
. ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Error] Compiler: Had 1 structural errors after macro expansion.
while executing phase "expand macros" on sentence at
Source(expandMacroRequires.k)
Location(12,10,12,49)
10 changes: 7 additions & 3 deletions kernel/src/main/java/org/kframework/compile/ExpandMacros.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,20 @@ private Sentence check(Sentence s) {
* contain macros that have not been expanded.
*/
if (s instanceof RuleOrClaim){
new VisitK() {
VisitK visitor = new VisitK() {
@Override
public void apply(KApply k) {
Option<Att> atts = mod.attributesFor().get(k.klabel());
if (atts.isDefined() && mod.attributesFor().apply(k.klabel()).getMacro().isDefined()) {
errors.add(KEMException.compilerError("Rule contains macro symbol that was not expanded", s));
}
k.klist().items().stream().forEach(i -> super.apply(i));
k.klist().items().forEach(super::apply);
}
}.accept(((RuleOrClaim) s).body());
};

visitor.accept(((RuleOrClaim) s).body());
visitor.accept(((RuleOrClaim) s).requires());
visitor.accept(((RuleOrClaim) s).ensures());
}

if (!errors.isEmpty()) {
Expand Down

0 comments on commit dfc06a5

Please sign in to comment.