Skip to content

Commit

Permalink
Disallow empty PVL enums in PVLToCol transform
Browse files Browse the repository at this point in the history
An enum that does not define any enumeration constants is now a parse error.
  • Loading branch information
wandernauta committed Oct 7, 2024
1 parent dc107f0 commit d2c1d40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/parsers/vct/parsers/transform/PVLToCol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ case class PVLToCol[G](

def convert(implicit enum: EnumDeclContext): Enum[G] =
enum match {
case EnumDecl0(_, name, _, constants, _, _) =>
new vct.col.ast.Enum[G](constants.map(convertConstants(_)).getOrElse(
Nil
))(origin(enum).sourceName(convert(name)))
case EnumDecl0(_, name, _, Some(constants), _, _) =>
new vct.col.ast.Enum[G](convertConstants(constants))(origin(enum).sourceName(convert(name)))
case _ =>
fail(enum, "This enumeration must specify at least one constant")
}

def convertConstants(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class Test {
enum AB { A, B }
"""

vercors should error withCode "parseError" in "pvl/empty enum" pvl """
enum E { }
"""

vercors should error withCode "parseError" in "pvl/empty enum with added comma" pvl """
enum E { , }
"""

vercors should verify using silicon in "pvl/enum return" pvl """
enum AB { A, B }
Expand Down

0 comments on commit d2c1d40

Please sign in to comment.