Skip to content

Enumerative option arguments are not validated by scalac #10756

Closed
@prolativ

Description

@prolativ

Minimized code

$ scalac -source xyz /tmp/scala-src/Foo.scala

Output

exception occurred while parsing /tmp/scala-src/Foo.scala exception occurred while compiling /tmp/scala-src/Foo.scala java.lang.IllegalArgumentException: enum case not found: xyz while compiling /tmp/scala-src/Foo.scala Exception in thread "main" java.lang.IllegalArgumentException: enum case not found: xyz at dotty.tools.dotc.config.SourceVersion$.valueOf(SourceVersion.scala:12) at dotty.tools.dotc.config.Feature$.sourceVersionSetting(Feature.scala:77) at dotty.tools.dotc.config.Feature$.sourceVersion(Feature.scala:83) at dotty.tools.dotc.config.Feature$.migrateTo3(Feature.scala:85) at dotty.tools.dotc.parsing.Scanners$Scanner.(Scanners.scala:165) at dotty.tools.dotc.parsing.Parsers$Parser.(Parsers.scala:174) at dotty.tools.dotc.typer.FrontEnd.parse$$anonfun$1(FrontEnd.scala:55) at dotty.tools.dotc.typer.FrontEnd$$Lambda$9294/000000000000000000.apply$mcV$sp(Unknown Source) at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:43) at dotty.tools.dotc.typer.FrontEnd.parse(FrontEnd.scala:67) at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$1(FrontEnd.scala:108) at dotty.tools.dotc.typer.FrontEnd$$Lambda$9293/000000000000000000.applyVoid(Unknown Source) at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15) at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.immutable.List.foreach(List.scala:333) at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:108) at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:185) at dotty.tools.dotc.Run$$Lambda$9288/000000000000000000.applyVoid(Unknown Source) at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15) at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323) at dotty.tools.dotc.Run.runPhases$5(Run.scala:195) at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:203) at dotty.tools.dotc.Run$$Lambda$9251/000000000000000000.apply$mcV$sp(Unknown Source) at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12) at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67) at dotty.tools.dotc.Run.compileUnits(Run.scala:210) at dotty.tools.dotc.Run.compileSources(Run.scala:147) at dotty.tools.dotc.Run.compile(Run.scala:129) at dotty.tools.dotc.Driver.doCompile(Driver.scala:38) at dotty.tools.dotc.Driver.process(Driver.scala:193) at dotty.tools.dotc.Driver.process(Driver.scala:162) at dotty.tools.dotc.Driver.process(Driver.scala:174) at dotty.tools.dotc.Driver.main(Driver.scala:201) at dotty.tools.dotc.Main.main(Main.scala)

Expectation

If a scalac setting is defined as a ChoiceSetting e.g.

val source: Setting[String] = ChoiceSetting("-source", "source version", "source version", List("3.0", "3.1", "3.0-migration", "3.1-migration"), "3.0").withAbbreviation("--source")

but an argument out of the allow list is passed, scalac should exit immediately and display an error message instead of accepting an invalid option which will later cause an exception or, even worse, not fail explicitly at all but run compilation with wrong settings

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions