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

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

Closed
romaincomeau opened this issue Feb 22, 2024 · 1 comment · Fixed by #19774
Closed

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

romaincomeau opened this issue Feb 22, 2024 · 1 comment · Fixed by #19774
Labels
itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label
Milestone

Comments

@romaincomeau
Copy link

romaincomeau commented Feb 22, 2024

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)
@romaincomeau romaincomeau added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 22, 2024
@i10416
Copy link
Contributor

i10416 commented Feb 24, 2024

It seems similar to #18265 fixed by #18743. Did you try compiling it with nightly?

I tried with the current master branch and it won't crash.

i10416 added a commit to i10416/dotty that referenced this issue Feb 24, 2024
Add a test to confirm issue#19762 is solved.
bishabosha added a commit that referenced this issue Feb 24, 2024
close #19762 and close
#19755 too.
Add a test to confirm issue#19762 is solved.
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
@Kordyjan Kordyjan modified the milestones: 3.4.2, 3.5.0 May 10, 2024
WojciechMazur pushed a commit that referenced this issue Jul 1, 2024
Add a test to confirm issue#19762 is solved.

[Cherry-picked 2a1d1b3]
WojciechMazur pushed a commit that referenced this issue Jul 1, 2024
Add a test to confirm issue#19762 is solved.

[Cherry-picked 2a1d1b3]
WojciechMazur pushed a commit that referenced this issue Jul 2, 2024
Add a test to confirm issue#19762 is solved.

[Cherry-picked 2a1d1b3]
WojciechMazur added a commit that referenced this issue Jul 2, 2024
Backports #19774 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants