Skip to content

Dotty crash declaring a function that returns an int 0a #19755

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

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

Dotty crash declaring a function that returns an int 0a #19755

romaincomeau opened this issue Feb 21, 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 21, 2024

I was trying to see what kind of error message would come up if I tried compiling0a instead of 0 and stumbled upon a compiler crash.

Compiler version

scala 3.3.1

Minimized code

trait Monoid[A]:
  def combine(a1: A, a2: A): A
  def empty: A

object Monoid:
  lazy val intAddition: Monoid[Int] = new:
    def combine(x: Int, y: Int) = x + y
    val empty = 0a
end Monoid

Output (click arrow to expand)

romaincomeau@phoenix fpinscala2 % scala-cli compile --server=false src/main/scala/fpinscala/exercises/monoids/Minimized.scala
-- [E018] Syntax Error: /Users/romaincomeau/dev/git/fpinscala2/src/main/scala/fpinscala/exercises/monoids/Minimized.scala:8:18
8 |    val empty = 0a
  |                  ^
  |                  expression expected but unindent found
  |
  | longer explanation available when compiling with `-explain`
error while checking  {
  def combine(x: Int, y: Int) = x + y
  val empty = 0 a null
}
error while checking new  {
  def combine(x: Int, y: Int) = x + y
  val empty = 0 a null
}
error while checking lazy val intAddition: Monoid[Int] =
  new  {
    def combine(x: Int, y: Int) = x + y
    val empty = 0 a null
  }
error while checking  {
  lazy val intAddition: Monoid[Int] =
    new  {
      def combine(x: Int, y: Int) = x + y
      val empty = 0 a null
    }
}
error while checking module object Monoid {
  lazy val intAddition: Monoid[Int] =
    new  {
      def combine(x: Int, y: Int) = x + y
      val empty = 0 a null
    }
}
error while checking package <empty> {
  trait Monoid[A] {
    def combine(a1: A, a2: A): A
    def empty: A
  }
  module object Monoid {
    lazy val intAddition: Monoid[Int] =
      new  {
        def combine(x: Int, y: Int) = x + y
        val empty = 0 a null
      }
  }
}
exception occurred while parser /Users/romaincomeau/dev/git/fpinscala2/src/main/scala/fpinscala/exercises/monoids/Minimized.scala

  exception occurred while compiling List(/Users/romaincomeau/dev/git/fpinscala2/src/main/scala/fpinscala/exercises/monoids/Minimized.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: -classpath /Users/romaincomeau/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.1/scala3-library_3-3.3.1.jar:/Users/romaincomeau/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.10/scala-library-2.13.10.jar -d /Users/romaincomeau/dev/git/fpinscala2/src/main/scala/fpinscala/exercises/monoids/.scala-build/monoids_103be31561-73523f4214/classes/main -java-output-version 17 -sourceroot /Users/romaincomeau/dev/git/fpinscala2/src/main/scala/fpinscala/exercises/monoids

                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      =  {
  def combine(x: Int, y: Int) = x + y
  val empty = 0 a null
} # -1,
parent span = <117..180>,
child       = val empty = 0 a null # -1,
child span  = [166..170..181]
	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.dotc.Main.main(Main.scala)
Compilation failed
@romaincomeau romaincomeau added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 21, 2024
@som-snytt
Copy link
Contributor

I updated scala-cli and verified the error. I see that checkPositions is always on.

There is a normal error on latest 3.4.2:

➜  ~/projects/dotty/bin/scalac -d /tmp/sandbox -Ycheck:all -java-output-version 21 i19755.scala
-- Error: i19755.scala:9:17 --------------------------------------------------------------------------------------------
9 |    val empty = 0a
  |                 ^
  |                 end of statement expected but identifier found
1 error found
➜  ~/projects/dotty/bin/scalac -version
Scala compiler version 3.4.2-RC1-bin-SNAPSHOT-git-e54be6e -- Copyright 2002-2024, LAMP/EPFL

Also, same for 42a, so it's not a weird leading zero bug.

@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
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