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 on new line after extension def without result type or RHS #18265

Closed
prolativ opened this issue Jul 21, 2023 · 2 comments · Fixed by #18743
Closed

Crash on new line after extension def without result type or RHS #18265

prolativ opened this issue Jul 21, 2023 · 2 comments · Fixed by #18743
Labels
area:parser itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Milestone

Comments

@prolativ
Copy link
Contributor

prolativ commented Jul 21, 2023

Compiler version

3.2.0, 3.3.0, 3.3.2-RC1-bin-20230720-98b452d-NIGHTLY
Used not to crash in 3.1.0

Minimized code

trait Foo

val foo = new Foo:
  extension (s: String)
    def twice

(Note the empty line at the end)

Output (click arrow to expand)

-- [E019] Syntax Error: /Users/mpalka/Projects/besom/Crash.scala:5:13 ----------
5 |    def twice
  |             ^
  |             Missing return type
  |
  | longer explanation available when compiling with `-explain`
error while checking  extends Foo {
  extension (s: String) def twice = null
}
error while checking new Foo {
  extension (s: String) def twice = null
}
error while checking val foo =
  new Foo {
    extension (s: String) def twice = null
  }
error while checking package <empty> {
  trait Foo {}
  val foo =
    new Foo {
      extension (s: String) def twice = null
    }
}
exception occurred while parser /Users/mpalka/Projects/besom/Crash.scala
exception occurred while compiling /Users/mpalka/Projects/besom/Crash.scala
java.lang.AssertionError: assertion failed: position error, parent span does not contain child span
parent      =  extends Foo {
  extension (s: String) def twice = null
} # -1,
parent span = <21..67>,
child       = extension (s: String) def twice = null # -1,
child span  = [32..68] while compiling /Users/mpalka/Projects/besom/Crash.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: position error, parent span does not contain child span
parent      =  extends Foo {
  extension (s: String) def twice = null
} # -1,
parent span = <21..67>,
child       = extension (s: String) def twice = null # -1,
child span  = [32..68]
        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.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:437)
        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:247)
        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:263)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:271)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:280)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:280)
        at dotty.tools.dotc.Run.compileSources(Run.scala:195)
        at dotty.tools.dotc.Run.compile(Run.scala:179)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:163)
        at dotty.tools.dotc.Driver.process(Driver.scala:175)
        at dotty.tools.dotc.Driver.main(Driver.scala:205)
        at dotty.tools.dotc.Main.main(Main.scala)

Expectations

The compilation should fail but without a crash. Note that there's no crash if the empty line gets removed from the end of the file.

@prolativ prolativ added itype:bug itype:crash regression This worked in a previous version but doesn't anymore labels Jul 21, 2023
@Kordyjan Kordyjan added area:parser Spree Suitable for a future Spree labels Jul 24, 2023
@scala-center-bot
Copy link

This issue was picked for the Issue Spree No. 35 of 22 August 2023 which takes place in 7 days. @jan-pieter, @hamzaremmal, @XLPI will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

hamzaremmal pushed a commit to hamzaremmal/scala3 that referenced this issue Aug 22, 2023
i10416 added a commit to i10416/dotty that referenced this issue Oct 22, 2023
This commit fixes a bug that causes Scala compiler to crash due to position error
when an extension method folowed by a newline has neither type annotation nor `= <expr>`.
i10416 added a commit to i10416/dotty that referenced this issue Oct 22, 2023
This commit fixes a bug that causes Scala compiler to crash due to position error
when an extension method followed by a newline has neither type annotation nor `= <expr>`.
i10416 added a commit to i10416/dotty that referenced this issue Oct 22, 2023
This commit fixes a bug that causes Scala compiler to crash due to position error
when an extension method followed by a newline has neither type annotation nor `= <expr>`.

This commit is based on scala#18445.

Co-Authored-By: @hamzaremmal
@FlorianCassayre
Copy link
Contributor

Here is another minimized program that appear to trigger the same issue:

given A with
  def a

Doesn't matter whether A is defined or not; the compiler should not crash in either case.

(again, notice the trailing line!)

@mbovel mbovel removed the Spree Suitable for a future Spree label Jan 14, 2024
hamzaremmal added a commit that referenced this issue Feb 1, 2024
close #18265 
This commit fixes a bug that causes Scala compiler to crash due to
position error when an extension method followed by a newline has
neither type annotation nor `= <expr>`.

This commit is based on #18445.

Co-Authored-By: @hamzaremmal
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
WojciechMazur pushed a commit that referenced this issue Jun 28, 2024
This commit fixes a bug that causes Scala compiler to crash due to position error
when an extension method followed by a newline has neither type annotation nor `= <expr>`.

This commit is based on #18445.

Co-Authored-By: @hamzaremmal

[Cherry-picked caf30e3]
WojciechMazur pushed a commit that referenced this issue Jun 30, 2024
This commit fixes a bug that causes Scala compiler to crash due to position error
when an extension method followed by a newline has neither type annotation nor `= <expr>`.

This commit is based on #18445.

Co-Authored-By: @hamzaremmal

[Cherry-picked caf30e3]
WojciechMazur added a commit that referenced this issue Jul 1, 2024
…" to LTS (#20876)

Backports #18743 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
area:parser itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Projects
None yet
5 participants