Skip to content

Whitespace-sensitive AssertionError somewhere in the typer (parser stability) #5004

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
sir-wabbit opened this issue Aug 24, 2018 · 4 comments

Comments

@sir-wabbit
Copy link

sir-wabbit commented Aug 24, 2018

// The bug is whitespace sensitive!!!
object i0 {
1 match {
def this(): Int
  def this()
}
}
Exception in thread "main" java.lang.AssertionError: assertion failed
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:37)
	at dotty.tools.dotc.core.Types$MethodType.<init>(Types.scala:2941)
	at dotty.tools.dotc.core.Types$CachedMethodType.<init>(Types.scala:2958)
	at dotty.tools.dotc.core.Types$MethodTypeCompanion.apply(Types.scala:3026)
	at dotty.tools.dotc.core.Types$MethodTypeCompanion.fromSymbols(Types.scala:3022)
	at dotty.tools.dotc.typer.NamerContextOps.$anonfun$1(Namer.scala:144)
	at scala.collection.immutable.List.$anonfun$foldRight$1(List.scala:405)
	at scala.collection.immutable.List.foldRight(List.scala:86)
	at scala.collection.TraversableOnce.$colon$bslash(TraversableOnce.scala:153)
	at scala.collection.TraversableOnce.$colon$bslash$(TraversableOnce.scala:153)
	at scala.collection.AbstractTraversable.$colon$bslash(Traversable.scala:104)
	at dotty.tools.dotc.typer.NamerContextOps.methodType(Namer.scala:144)
	at dotty.tools.dotc.typer.Namer.wrapMethType$1(Namer.scala:1196)
	at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1210)
	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:721)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:801)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:746)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:237)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:184)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:186)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:343)
	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:1771)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1796)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1868)

AE-4f7e66f7ee706c59e8d8ba100db9d2bf0152b119

@sir-wabbit sir-wabbit changed the title AssertionError somewhere in the typer (parser stability) Whitespace-sensitive AssertionError somewhere in the typer (parser stability) Aug 24, 2018
@Blaisorblade
Copy link
Contributor

Blaisorblade commented Aug 26, 2018

This is less whitespace-sensitive:

object i0 {
  1 match {
    case null =>
      def this(): Int
      def this()
  }
}
package <empty> {
  module object i0 {
    1 match
      {
        case null =>
          def <init>(): Unit =
            {
              <init>(null)
              ()
            }
          def <init>() =
            {
              <init>(null)
              ()
            }
          <empty>
      }
  }
}

and when naming the second <init> in Namer.defDefSig, the ddef.name is <init> while sym.name is $init$$1 — apparently, it's <init>.freshened created by checkNoConflict because of the name-conflict. The code assumes they're the same and produces NoType otherwise. However, fixing that via this one-liner leads to another crash:

diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala
index f8d83964e..5281f7a0d 100644
--- a/compiler/src/dotty/tools/dotc/typer/Namer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala
@@ -1158,8 +1158,8 @@ class Namer { typer: Typer =>

   /** The type signature of a DefDef with given symbol */
   def defDefSig(ddef: DefDef, sym: Symbol)(implicit ctx: Context) = {
-    val DefDef(name, tparams, vparamss, _, _) = ddef
-    val isConstructor = name == nme.CONSTRUCTOR
+    val DefDef(_, tparams, vparamss, _, _) = ddef
+    val isConstructor = sym.name == nme.CONSTRUCTOR

     // The following 3 lines replace what was previously just completeParams(tparams).
     // But that can cause bad bounds being computed, as witnessed by

new crash:

-- [E040] Syntax Error: tests/neg/i5004.scala:5:16 -----------------------------
5 |      def this(): Int
  |                ^
  |                '=' expected, but ':' found
-- [E040] Syntax Error: tests/neg/i5004.scala:7:2 ------------------------------
7 |  }
  |  ^
  |  '=' expected, but '}' found
8 |}
-- Error: tests/neg/i5004.scala:6:10 -------------------------------------------
6 |      def this()
  |      ^^^^^^^^^^
  |      <init> is already defined as constructor <local i0$>
-- Error: tests/neg/i5004.scala:5:6 --------------------------------------------
5 |      def this(): Int
  |      ^
  |      too many arguments for constructor <local i0$>: (): i0.<local i0$>
exception occurred while typechecking tests/neg/i5004.scala
exception occurred while compiling tests/neg/i5004.scala
Exception in thread "main" java.lang.AssertionError: assertion failed
	at scala.Predef$.assert(Predef.scala:204)
	at dotty.tools.dotc.core.Contexts$Context.thisCallArgContext(Contexts.scala:354)
	at dotty.tools.dotc.typer.Applications.argCtx(Applications.scala:685)
	at dotty.tools.dotc.typer.Applications.argCtx$(Applications.scala:684)
	at dotty.tools.dotc.typer.Typer.argCtx(Typer.scala:82)
	at dotty.tools.dotc.typer.Applications.$anonfun$typedApply$1(Applications.scala:694)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:693)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:794)
	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:691)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:82)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1828)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1879)

Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 26, 2018
But this isn't a full fix and might be a bad idea.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 26, 2018
But this isn't a full fix and might be a bad idea.
@sir-wabbit
Copy link
Author

This might be the same bug:

object i0 {
  {
    def this
    def this
  }
}
Exception in thread "main" java.lang.AssertionError: assertion failed
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:37)
	at dotty.tools.dotc.core.Types$MethodType.<init>(Types.scala:2941)
	at dotty.tools.dotc.core.Types$CachedMethodType.<init>(Types.scala:2958)
	at dotty.tools.dotc.core.Types$MethodTypeCompanion.apply(Types.scala:3026)
	at dotty.tools.dotc.core.Types$MethodTypeCompanion.fromSymbols(Types.scala:3022)
	at dotty.tools.dotc.typer.NamerContextOps.$anonfun$1(Namer.scala:144)
	at scala.collection.immutable.List.$anonfun$foldRight$1(List.scala:405)
	at scala.collection.immutable.List.foldRight(List.scala:86)
	at scala.collection.TraversableOnce.$colon$bslash(TraversableOnce.scala:153)
	at scala.collection.TraversableOnce.$colon$bslash$(TraversableOnce.scala:153)
	at scala.collection.AbstractTraversable.$colon$bslash(Traversable.scala:104)
	at dotty.tools.dotc.typer.NamerContextOps.methodType(Namer.scala:144)
	at dotty.tools.dotc.typer.Namer.wrapMethType$1(Namer.scala:1196)
	at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1210)
	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:721)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:801)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:746)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:237)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:184)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:186)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:343)
	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:1771)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1796)

AE-4f7e66f7ee706c59e8d8ba100db9d2bf0152b119

@Blaisorblade
Copy link
Contributor

Yep, seems very likely the same from my analysis!

@Blaisorblade
Copy link
Contributor

Blaisorblade commented Aug 27, 2018

@odersky Can you take a look at this? This is the bug with freshened constructors (tho they're under a block!):

object i0 {
  {
    def this
    def this
  }
}

odersky added a commit that referenced this issue Aug 30, 2018
odersky added a commit that referenced this issue Feb 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants