Skip to content

Crash while declaring a new anonymous subtype with extra paren #19762

@romaincomeau

Description

@romaincomeau

Compiler version

compiler version: version 3.3.1

Minimized code

Notice the extra parenthese in
def combine(x: Int, y: Int))

trait Monoid[A]: def combine(x: A, y: A): A def empty: A object Monoid: lazy val addInt: Monoid[Int] = new: val empty = 0 def combine(x: Int, y: Int)) = x + y

Output (click arrow to expand)

romaincomeau@phoenix monoids % scalac /tmp/extra_paren.scala -- [E019] Syntax Error: /tmp/extra_paren.scala:8:31 ---------------------------- 8 | def combine(x: Int, y: Int)) = x + y | ^ | Missing return type | | longer explanation available when compiling with `-explain` error while checking { val empty = 0 def combine(x: Int, y: Int) = null } error while checking new { val empty = 0 def combine(x: Int, y: Int) = null } error while checking lazy val addInt: Monoid[Int] = new { val empty = 0 def combine(x: Int, y: Int) = null } error while checking { lazy val addInt: Monoid[Int] = new { val empty = 0 def combine(x: Int, y: Int) = null } } error while checking module object Monoid { lazy val addInt: Monoid[Int] = new { val empty = 0 def combine(x: Int, y: Int) = null } } error while checking package <empty> { trait Monoid[A] { def combine(x: A, y: A): A def empty: A } module object Monoid { lazy val addInt: Monoid[Int] = new { val empty = 0 def combine(x: Int, y: Int) = null } } } exception occurred while parser /tmp/extra_paren.scala exception occurred while compiling List(/tmp/extra_paren.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: <no file> during phase: <no phase> mode: Mode(ImplicitsEnabled) library version: version 2.13.10 compiler version: version 3.3.1 settings: tree: EmptyTree tree position: :<unknown> tree type: <notype> symbol: val <none> call site: package <root> in module class <root> == Source file context for tree position == Exception in thread "main" java.lang.AssertionError: assertion failed: position error, parent span does not contain child span parent = { val empty = 0 def combine(x: Int, y: Int) = null } # -1, parent span = <110..173>, child = def combine(x: Int, y: Int) = null # -1, child span = [137..141..175]	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)	at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:175)	at dotty.tools.dotc.ast.Positioned.check$1$$anonfun$3(Positioned.scala:205)	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.ast.Positioned.check$1(Positioned.scala:205)	at dotty.tools.dotc.ast.Positioned.checkPos(Positioned.scala:226)	at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:200)	at dotty.tools.dotc.ast.Positioned.checkPos(Positioned.scala:226)	at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:200)	at dotty.tools.dotc.ast.Positioned.checkPos(Positioned.scala:226)	at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:200)	at dotty.tools.dotc.ast.Positioned.check$1$$anonfun$3(Positioned.scala:205)	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.ast.Positioned.check$1(Positioned.scala:205)	at dotty.tools.dotc.ast.Positioned.checkPos(Positioned.scala:226)	at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:200)	at dotty.tools.dotc.ast.Positioned.checkPos(Positioned.scala:226)	at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:200)	at dotty.tools.dotc.ast.Positioned.check$1$$anonfun$3(Positioned.scala:205)	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.ast.Positioned.check$1(Positioned.scala:205)	at dotty.tools.dotc.ast.Positioned.checkPos(Positioned.scala:226)	at dotty.tools.dotc.parsing.Parser.parse$$anonfun$1(ParserPhase.scala:38)	at dotty.tools.dotc.parsing.Parser.parse$$anonfun$adapted$1(ParserPhase.scala:39)	at scala.Function0.apply$mcV$sp(Function0.scala:42)	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:440)	at dotty.tools.dotc.parsing.Parser.parse(ParserPhase.scala:39)	at dotty.tools.dotc.parsing.Parser.runOn$$anonfun$1(ParserPhase.scala:48)	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.parsing.Parser.runOn(ParserPhase.scala:48)	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:1321)	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:67)	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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions