Skip to content

Assertion error when compiling invalid @annotation #3557

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
helloqirun opened this issue Nov 26, 2017 · 2 comments
Closed

Assertion error when compiling invalid @annotation #3557

helloqirun opened this issue Nov 26, 2017 · 2 comments

Comments

@helloqirun
Copy link

scalac can compile but dotc crashes.

$ dotc -version

Dotty compiler version 0.5.0-bin-SNAPSHOT-git-4fefb64 -- Copyright 2002-2017, LAMP/EPFL

$ dotc abc.scala

-- [E080] Syntax Error: abc.scala:10:5 -----------------------------------------
10 |    @f.varargs
   |     ^
   | missing parameter type for parameter values, expected = ?{ varargs: ? }

longer explanation available when compiling with `-explain`

exception occurred while typechecking abc.scala

exception occurred while compiling abc.scala
Exception in thread "main" java.lang.AssertionError: assertion failed
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:38)
	at dotty.tools.dotc.core.Types$CachedTermRef.<init>(Types.scala:2014)
	at dotty.tools.dotc.core.Uniques$NamedTypeUniques.newType$1(Uniques.scala:60)
	at dotty.tools.dotc.core.Uniques$NamedTypeUniques.enterIfNew(Uniques.scala:66)
	at dotty.tools.dotc.core.Types$TermRef$.apply(Types.scala:2046)
	at dotty.tools.dotc.core.Types$TermRef.withPrefix(Types.scala:1998)
	at dotty.tools.dotc.core.Types$NamedType.derivedSelect(Types.scala:1915)
	at dotty.tools.dotc.ast.TreeTypeMap$$anon$1.apply(TreeTypeMap.scala:56)
	at dotty.tools.dotc.ast.TreeTypeMap.mapType(TreeTypeMap.scala:62)
	at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:89)
	at dotty.tools.dotc.ast.TreeTypeMap.apply(TreeTypeMap.scala:140)
	at dotty.tools.dotc.ast.tpd$TreeOps$.loop$1(tpd.scala:650)
	at dotty.tools.dotc.ast.tpd$TreeOps$.changeOwner$extension(tpd.scala:653)
	at dotty.tools.dotc.typer.Typer.typedTypedSplice(Typer.scala:1549)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1674)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1690)
	at dotty.tools.dotc.typer.Typer.op$40(Typer.scala:1707)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1703)
<snipped>

$ cat abc.scala

class C1 {
  @annotation.varargs
  def f(values: String*) = ()
}
class C2 {
  @scala.annotation.varargs
  def f(values: String*) = ()
  def g: String => Int = s => hashCode
  class C3 {
    @f.varargs
    def f(values: String) = ()
  }
}
@allanrenucci
Copy link
Contributor

Not sure why it compiles with scalac. @f.varargs doesn't make much sense.

$ scalac -d out tests/allan/Test.scala -Xprint:typer
[[syntax trees at end of                     typer]] // Test.scala
package <empty> {
  class C1 extends scala.AnyRef {
    def <init>(): C1 = {
      C1.super.<init>();
      ()
    };
    @scala.annotation.varargs def f(values: String*): Unit = ()
  };
  class C2 extends scala.AnyRef {
    def <init>(): C2 = {
      C2.super.<init>();
      ()
    };
    @scala.annotation.varargs def f(values: String*): Unit = ();
    def g: String => Int = ((s: String) => C2.this.hashCode());
    class C3 extends scala.AnyRef {
      def <init>(): C2.this.C3 = {
        C3.super.<init>();
        ()
      };
      @<error> def f(values: String): Unit = ()
    }
  }
}

@allanrenucci allanrenucci changed the title crash on compilable code: assertion failed at dotty.DottyPredef$.assertFail(DottyPredef.scala:38) Assertion error when compiling invalid @annotation Nov 26, 2017
@allanrenucci
Copy link
Contributor

Here is a minimised test case:

class C2 {
  def f(values: String*) = ()
  class C3 {
    @f.varargs
    def f(values: String) = ()
  }
}
Stacktrace
> dotc -d out tests/allan/Test.scala
[warn] Multiple main classes detected.  Run 'show discoveredMainClasses' to see the list
[warn] Multiple main classes detected.  Run 'show discoveredMainClasses' to see the list
[info] Running dotty.tools.dotc.Main -classpath /Users/renucci/projects/dotty/library/target/scala-2.12/dotty-library_2.12-0.5.0-bin-SNAPSHOT-nonbootstrapped.jar -d out tests/allan/Test.scala
-- [E080] Syntax Error: tests/allan/Test.scala:4:5 -----------------------------
4 |    @f.varargs
  |     ^
  |   missing parameter type for parameter values, expected = ?{ varargs: ? }

longer explanation available when compiling with -explain
exception occurred while typechecking tests/allan/Test.scala
exception occurred while compiling tests/allan/Test.scala
Exception in thread "main" java.lang.AssertionError: assertion failed
at scala.Predef$.assert(Predef.scala:204)
at dotty.tools.dotc.core.Types$CachedTermRef.(Types.scala:2014)
at dotty.tools.dotc.core.Uniques$NamedTypeUniques.newType$1(Uniques.scala:60)
at dotty.tools.dotc.core.Uniques$NamedTypeUniques.enterIfNew(Uniques.scala:66)
at dotty.tools.dotc.core.Types$TermRef$.apply(Types.scala:2046)
at dotty.tools.dotc.core.Types$TermRef.withPrefix(Types.scala:1998)
at dotty.tools.dotc.core.Types$NamedType.derivedSelect(Types.scala:1915)
at dotty.tools.dotc.ast.TreeTypeMap$$anon$1.apply(TreeTypeMap.scala:56)
at dotty.tools.dotc.ast.TreeTypeMap.mapType(TreeTypeMap.scala:62)
at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:89)
at dotty.tools.dotc.ast.TreeTypeMap.apply(TreeTypeMap.scala:140)
at dotty.tools.dotc.ast.tpd$TreeOps$.loop$1(tpd.scala:650)
at dotty.tools.dotc.ast.tpd$TreeOps$.changeOwner$extension(tpd.scala:653)
at dotty.tools.dotc.typer.Typer.typedTypedSplice(Typer.scala:1549)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1674)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1690)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1707)
at dotty.tools.dotc.reporting.trace$.apply(trace.scala:23)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1703)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1764)
at dotty.tools.dotc.typer.Applications.$anonfun$typedApply$1(Applications.scala:669)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:667)
at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:767)
at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:665)
at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:69)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1642)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1690)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1707)
at dotty.tools.dotc.reporting.trace$.apply(trace.scala:23)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1703)
at dotty.tools.dotc.typer.Namer.$anonfun$typedAheadExpr$1(Namer.scala:942)
at dotty.tools.dotc.typer.Namer.typedAheadImpl(Namer.scala:932)
at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:942)
at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1060)
at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1072)
at dotty.tools.dotc.typer.Namer.lhsType$lzycompute$1(Namer.scala:1073)
at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1073)
at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1090)
at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1098)
at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1164)
at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:736)
at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:780)
at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:758)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:241)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeInfo$1(SymDenotations.scala:204)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:206)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:347)
at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:1595)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1620)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1689)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1707)
at dotty.tools.dotc.reporting.trace$.apply(trace.scala:23)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1703)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1729)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1752)
at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:623)
at dotty.tools.dotc.typer.Typer.$anonfun$typedBlock$1(Typer.scala:626)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:625)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1649)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1690)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1707)
at dotty.tools.dotc.reporting.trace$.apply(trace.scala:23)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1703)
at dotty.tools.dotc.typer.Typer.$anonfun$typedFunction$1(Typer.scala:852)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedFunction(Typer.scala:699)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1651)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1690)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1707)
at dotty.tools.dotc.reporting.trace$.apply(trace.scala:23)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1703)
at dotty.tools.dotc.typer.Typer.adaptNoArgsUnappliedMethod$1(Typer.scala:2134)
at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:2222)
at dotty.tools.dotc.typer.Typer.adaptInterpolated(Typer.scala:2347)
at dotty.tools.dotc.typer.Typer.$anonfun$adapt$3(Typer.scala:1873)
at dotty.tools.dotc.reporting.trace$.apply(trace.scala:23)
at dotty.tools.dotc.typer.Typer.$anonfun$adapt$1(Typer.scala:1869)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:1869)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1707)
at dotty.tools.dotc.reporting.trace$.apply(trace.scala:23)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1703)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1764)
at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:397)
at dotty.tools.dotc.typer.Typer.$anonfun$typedSelect$1(Typer.scala:431)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:395)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1623)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1689)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1707)
at dotty.tools.dotc.reporting.trace$.apply(trace.scala:23)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1703)
at dotty.tools.dotc.typer.Namer.$anonfun$typedAheadType$1(Namer.scala:939)
at dotty.tools.dotc.typer.Namer.typedAheadImpl(Namer.scala:932)
at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:939)
at dotty.tools.dotc.typer.Namer.typedAheadAnnotation(Namer.scala:948)
at dotty.tools.dotc.typer.Namer.typedAheadAnnotation(Namer.scala:947)
at dotty.tools.dotc.typer.Namer.typedAheadAnnotation(Namer.scala:945)
at dotty.tools.dotc.typer.Namer.$anonfun$addAnnotations$1(Namer.scala:705)
at dotty.tools.dotc.typer.Namer.$anonfun$addAnnotations$1$adapted(Namer.scala:704)
at scala.collection.immutable.List.foreach(List.scala:389)
at dotty.tools.dotc.typer.Namer.addAnnotations(Namer.scala:704)
at dotty.tools.dotc.typer.Namer.recur$2(Namer.scala:659)
at dotty.tools.dotc.typer.Namer.$anonfun$annotate$3(Namer.scala:671)
at dotty.tools.dotc.typer.Namer.$anonfun$annotate$3$adapted(Namer.scala:671)
at scala.collection.immutable.List.foreach(List.scala:389)
at dotty.tools.dotc.typer.Namer.annotate(Namer.scala:671)
at dotty.tools.dotc.typer.Namer.indexAndAnnotate(Namer.scala:717)
at dotty.tools.dotc.typer.Namer$ClassCompleter.completeInCreationContext(Namer.scala:911)
at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:758)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:241)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeInfo$1(SymDenotations.scala:204)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:206)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:347)
at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:1595)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1620)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1689)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1707)
at dotty.tools.dotc.reporting.trace$.apply(trace.scala:23)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1703)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1729)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1752)
at dotty.tools.dotc.typer.Typer.$anonfun$typedClassDef$1(Typer.scala:1415)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1345)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1633)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1689)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1707)
at dotty.tools.dotc.reporting.trace$.apply(trace.scala:23)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1703)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1729)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1752)
at dotty.tools.dotc.typer.Typer.$anonfun$typedPackageDef$1(Typer.scala:1528)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1515)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1672)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1690)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1707)
at dotty.tools.dotc.reporting.trace$.apply(trace.scala:23)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1703)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1764)
at dotty.tools.dotc.typer.FrontEnd.$anonfun$typeCheck$1(FrontEnd.scala:64)
at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:32)
at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:62)
at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$7(FrontEnd.scala:93)
at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$7$adapted(FrontEnd.scala:93)
at scala.collection.immutable.List.foreach(List.scala:389)
at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:93)
at dotty.tools.dotc.Run.$anonfun$compileUnits$3(Run.scala:125)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at dotty.tools.dotc.util.Stats$.trackTime(Stats.scala:47)
at dotty.tools.dotc.Run.$anonfun$compileUnits$2(Run.scala:123)
at dotty.tools.dotc.Run.$anonfun$compileUnits$2$adapted(Run.scala:121)
at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:191)
at dotty.tools.dotc.Run.runPhases$1(Run.scala:121)
at dotty.tools.dotc.Run.$anonfun$compileUnits$1(Run.scala:141)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:86)
at dotty.tools.dotc.Run.compileUnits(Run.scala:107)
at dotty.tools.dotc.Run.compileSources(Run.scala:94)
at dotty.tools.dotc.Run.compile(Run.scala:78)
at dotty.tools.dotc.Driver.doCompile(Driver.scala:29)
at dotty.tools.dotc.Driver.process(Driver.scala:127)
at dotty.tools.dotc.Driver.process(Driver.scala:96)
at dotty.tools.dotc.Driver.process(Driver.scala:108)
at dotty.tools.dotc.Driver.main(Driver.scala:135)
at dotty.tools.dotc.Main.main(Main.scala)


odersky added a commit to dotty-staging/dotty that referenced this issue Jan 1, 2018
The test now compiles with errors, which is what we would expect.
@odersky odersky closed this as completed in a7a94b2 Jan 2, 2018
odersky added a commit that referenced this issue Jan 2, 2018
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

2 participants