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

dotty crashes while compiling this file (its an invalid scala program) #20511

Closed
rfdzan opened this issue Jun 2, 2024 · 2 comments · Fixed by #21178
Closed

dotty crashes while compiling this file (its an invalid scala program) #20511

rfdzan opened this issue Jun 2, 2024 · 2 comments · Fixed by #21178

Comments

@rfdzan
Copy link

rfdzan commented Jun 2, 2024

Compiler version

3.3.3

Minimized code

package PizzaPackage
import CrustSize.*
import CrustType.*
import Topping.*

// model the pizza
case class Pizza(
    crustSize: CrustSize,
    crustType: CrustType,
    toppings: Seq[Topping]
)
object Pizza:
  def price(p: Pizza): Double =
    calculatePrice(p.crustType, p.crustSize, p.toppings, toppingPrice, crustPrice)
  def calculatePrice(crustType: CrustType, crustSize: CrustSize, toppings: Seq[Topping], f: Topping => Double, g: (CrustType, CrustSize) => Double): Double =
    g(crustType, crustSize) + toppings.map(f).sum()     
  def toppingPrice(t: Topping): Double =
    t match
      case Cheese      => 0.35
      case BlackOlives => 0.45
      case GreenOlives => 0.77
      case Onions      => 0.20
      case Pepperoni   => 0.5

  def crustPrice(crustType: CrustType, crustSize: CrustSize): Double =
    (crustSize, crustType) match
      case (Small, _)       => 0.25
      case (Medium, _)      => 0.35
      case (Large, Thin)    => 0.50
      case (Large, Regular) => 1.00
      case (Large, Thick)   => 1.15
  // This line is a compiler error and seems to be the source of the crash. 
  export toppingPrice, crustPrice

enum CrustSize:
  case Small, Medium, Large
enum CrustType:
  case Thin, Thick, Regular
enum Topping:
  case Cheese, Pepperoni, BlackOlives, GreenOlives, Onions

@main def mainPizza =
  val myPizza = Pizza(
    CrustSize.Large,
    CrustType.Thick,
    Vector(Topping.Cheese, Topping.Pepperoni, Topping.Onions, Topping.BlackOlives)
  )
  println(Pizza.price(myPizza))

Output (click arrow to expand)

[31m[31m-- [E040] Syntax Error: Pizza.scala:32:21 --------------------------------------�[0m[0m
[31m32 |�[0m  [33mexport[0m toppingPrice, crustPrice
[31m[31m   |�[0m                     ^�[0m
[31m   |�[0m                     '.' expected, but ',' found
[31m[31m-- [E040] Syntax Error: Pizza.scala:34:0 ---------------------------------------�[0m[0m
[31m34 |�[0m[33menum[0m [35mCrustSize[0m:
[31m[31m   |�[0m^^^^�[0m
[31m   |�[0m'.' expected, but unindent found

  exception occurred while typechecking Pizza.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/lampepfl/dotty/issues/new/choose

     while compiling: Pizza.scala
        during phase: typer
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.12
    compiler version: version 3.3.3
            settings: 

Exception in thread "main" java.lang.Error: internal error: closing over non-method <overloaded PizzaPackage.Pizza.$anonfun>, pos = <1064..1064>
	at dotty.tools.dotc.typer.Typer.typedClosure(Typer.scala:1676)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3061)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3303)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1168)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3058)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
	at dotty.tools.dotc.typer.Typer.typedFunctionValue(Typer.scala:1630)
	at dotty.tools.dotc.typer.Typer.typedFunction(Typer.scala:1381)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3060)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
	at dotty.tools.dotc.typer.Typer.adaptNoArgsUnappliedMethod$1(Typer.scala:3926)
	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4069)
	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4277)
	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3590)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3303)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1656)
	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1646)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1656)
	at dotty.tools.dotc.typer.Namer$ClassCompleter.exportForwarders(Namer.scala:1103)
	at dotty.tools.dotc.typer.Namer$ClassCompleter.processExport$1(Namer.scala:1383)
	at dotty.tools.dotc.typer.Namer$ClassCompleter.process$1(Namer.scala:1404)
	at dotty.tools.dotc.typer.Namer$ClassCompleter.processExports(Namer.scala:1425)
	at dotty.tools.dotc.typer.Namer$ClassCompleter.completeInCreationContext(Namer.scala:1621)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:814)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeMembersNamed(SymDenotations.scala:2145)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:2115)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2166)
	at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:721)
	at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:900)
	at dotty.tools.dotc.typer.TypeAssigner.selectionType(TypeAssigner.scala:155)
	at dotty.tools.dotc.typer.TypeAssigner.selectionType$(TypeAssigner.scala:16)
	at dotty.tools.dotc.typer.Typer.selectionType(Typer.scala:117)
	at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:682)
	at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:756)
	at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:793)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3019)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3114)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3303)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:941)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1101)
	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:117)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3050)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3303)
	at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:2424)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3023)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3114)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3213)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3259)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2812)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3083)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3303)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:50)
	at scala.Function0.apply$mcV$sp(Function0.scala:42)
	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:440)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:50)
	at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:84)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:84)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:71)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:279)
	at dotty.tools.dotc.Run.compileSources(Run.scala:194)
	at dotty.tools.dotc.Run.compile(Run.scala:179)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
	at dotty.tools.dotc.Driver.process(Driver.scala:197)
	at dotty.tools.dotc.Driver.process(Driver.scala:165)
	at dotty.tools.dotc.Driver.process(Driver.scala:177)
	at dotty.tools.dotc.Driver.main(Driver.scala:207)
	at dotty.tools.MainGenericCompiler$.run$1(MainGenericCompiler.scala:162)
	at dotty.tools.MainGenericCompiler$.main(MainGenericCompiler.scala:186)
	at dotty.tools.MainGenericCompiler.main(MainGenericCompiler.scala)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at coursier.bootstrap.launcher.a.a(Unknown Source)
	at coursier.bootstrap.launcher.Launcher.main(Unknown Source)
@rfdzan rfdzan added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 2, 2024
@Gedochao Gedochao added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 3, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Jun 3, 2024

Dunno about 2.12.19 (🤔), but it definitely crashes on 3.5.1-RC1-bin-20240602-c6fbe6f-NIGHTLY-git-c6fbe6f and 3.3.4-RC1-bin-20240326-feeddb7-NIGHTLY-git-feeddb7

@KacperFKorban KacperFKorban self-assigned this Jul 11, 2024
@KacperFKorban
Copy link
Member

KacperFKorban commented Jul 11, 2024

Minimized example:

package pakiet

def toppingPrice(size: Int): Double = ???

def crustPrice(crustType: Double): Double = ???

export toppingPrice, crustPrice

Output:

-- [E040] Syntax Error: ~/bugs/i20511.scala:9:19 -----------------------
9 |export toppingPrice, crustPrice
  |                   ^
  |                   '.' expected, but ',' found
-- [E040] Syntax Error: ~/bugs/i20511.scala:10:0 -----------------------
10 |
   |^
   |'.' expected, but eof found

  exception occurred while typechecking ~/bugs/i20511.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/scala/scala3/issues/new/choose
  For non-enriched exceptions, compile with -Xno-enrich-error-messages.

     while compiling: ~/bugs/i20511.scala
        during phase: typer
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.14
    compiler version: version 3.6.0-RC1-bin-20240710-466676c-NIGHTLY-git-466676c
            settings: -classpath ~/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.6.0-RC1-bin-20240710-466676c-NIGHTLY/scala3-library_3-3.6.0-RC1-bin-20240710-466676c-NIGHTLY.jar:~/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.14/scala-library-2.13.14.jar -d ~/bugs/.scala-build/bugs_3200b05eac-f6fadb94cd/classes/main -java-output-version 11 -sourceroot ~/bugs

Exception in thread "main" java.lang.Error: internal error: closing over non-method <overloaded pakiet.$anonfun>, pos = <156..166>
        at dotty.tools.dotc.typer.Typer.typedClosure(Typer.scala:1981)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3447)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3520)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3597)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3601)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3712)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1419)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3443)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3520)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3597)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3601)
        at dotty.tools.dotc.typer.Typer.typedFunctionValue(Typer.scala:1896)
        at dotty.tools.dotc.typer.Typer.typedFunction(Typer.scala:1635)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3445)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3520)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3597)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3601)
        at dotty.tools.dotc.typer.Typer.adaptNoArgsUnappliedMethod$1(Typer.scala:4318)
        at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4471)
        at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4703)
        at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3975)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3597)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3601)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3712)
        at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1747)
        at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1737)
        at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1747)
        at dotty.tools.dotc.typer.Namer$ClassCompleter.exportForwarders(Namer.scala:1143)
        at dotty.tools.dotc.typer.Namer$ClassCompleter.processExport$1(Namer.scala:1445)
        at dotty.tools.dotc.typer.Namer$ClassCompleter.process$1(Namer.scala:1467)
        at dotty.tools.dotc.typer.Namer$ClassCompleter.processExports(Namer.scala:1488)
        at dotty.tools.dotc.typer.Namer$ClassCompleter.completeInCreationContext(Namer.scala:1712)
        at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:850)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:175)
        at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:190)
        at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:192)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3249)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3469)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3520)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3597)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3601)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3712)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:503)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53)
        at dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99)
        at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
        at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
        at scala.collection.immutable.List.prependedAll(List.scala:152)
        at scala.collection.immutable.List$.from(List.scala:685)
        at scala.collection.immutable.List$.from(List.scala:682)
        at scala.collection.IterableOps$WithFilter.map(Iterable.scala:900)
        at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:98)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:336)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:396)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:396)
        at dotty.tools.dotc.Run.compileSources(Run.scala:282)
        at dotty.tools.dotc.Run.compile(Run.scala:267)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.dotc.Driver.process(Driver.scala:201)
        at dotty.tools.dotc.Driver.process(Driver.scala:169)
        at dotty.tools.dotc.Driver.process(Driver.scala:181)
        at dotty.tools.dotc.Driver.main(Driver.scala:211)
        at dotty.tools.dotc.Main.main(Main.scala)
Compilation failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants