Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error message for duplicate user lists #2641

Merged
merged 2 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module CHECKDUPLICATELIST-SYNTAX
imports INT-SYNTAX
syntax MyList ::= List{Int,""}
endmodule

module CHECKDUPLICATELIST
imports CHECKDUPLICATELIST-SYNTAX
syntax MyList ::= List{Int,""}
endmodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Error] Compiler: Sort MyList previously declared as a user list at Source(checkDuplicateList.k) and Location(3,21,3,33)
Source(checkDuplicateList.k)
Location(8,21,8,33)
8 | syntax MyList ::= List{Int,""}
. ^~~~~~~~~~~~
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ object FlatModule {
val newImports = m.imports.map(f)
val newM = new Module(m.name, newImports, m.localSentences, m.att)
newM.checkSorts()
newM.checkUserLists()
newM
})
}
Expand Down
14 changes: 14 additions & 0 deletions kore/src/main/scala/org/kframework/definition/outer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,20 @@ case class Module(val name: String, val imports: Set[Import], localSentences: Se
case _ =>
}

def checkUserLists(): Unit = localSentences foreach {
case p@Production(_, _, srt, _, atts) =>
if (atts.contains(Att.USER_LIST)) {
val prev = importedSentences.find(s => s.isInstanceOf[Production]
&& s.asInstanceOf[Production].sort.equals(srt)
&& s.att.contains(Att.USER_LIST))
if (prev.isDefined)
throw KEMException.compilerError("Sort " + srt + " previously declared as a user list at "
+ prev.get.source.get() + " and "
+ prev.get.location.get(), p)
}
case _ =>
}

lazy val recordProjections = productions.flatMap(p => p.nonterminals.filter(_.name.isDefined).map(nt => "project:" ++ p.klabel.get.name ++ ":" ++ nt.name.get))
lazy val semanticCasts = allSorts.map("#SemanticCastTo" + _)
lazy val sortProjections = allSorts.map("project:" + _)
Expand Down