Closed
Description
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)