liufengyun / gestalt

gestalt : portable and solid macros for Scala
https://github.com/scalacenter/macros
31 stars 3 forks source link

@specialized does not work ? #98

Closed Russoul closed 6 years ago

Russoul commented 6 years ago

dotty code:

trait Addable[@specialized T]{
    def plus(a : T, b : T) : T
}

compiler error:

...
[info] exception occurred while typechecking ...
[info] exception occurred while compiling  ...
java.lang.AssertionError: assertion failed: no symbol for @specialized()  T
    at dotty.DottyPredef$.assertFail(DottyPredef.scala:39)
    at dotty.tools.dotc.typer.Namer.recur$5(Namer.scala:686)
    at dotty.tools.dotc.typer.Namer.annotate$$anonfun$1(Namer.scala:693)
    at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
    at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
    at scala.collection.immutable.List.foreach(List.scala:389)
    at dotty.tools.dotc.typer.Namer.annotate(Namer.scala:693)
    at dotty.tools.dotc.typer.Namer$ClassCompleter.completeInCreationContext(Namer.scala:931)
    at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:780)
    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$ClassDenotation.classInfo(SymDenotations.scala:1334)
    at dotty.tools.dotc.core.Types$ThisType.underlying(Types.scala:2124)
    at dotty.tools.dotc.core.Types$Type.goThis$1(Types.scala:601)
    at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:504)
    at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:644)
    at dotty.tools.dotc.core.Types$Type.memberExcluding(Types.scala:483)
    at dotty.tools.dotc.core.Types$Type.op$4(Types.scala:469)
    at dotty.tools.dotc.core.Types$Type.member(Types.scala:468)
    at dotty.tools.dotc.typer.NamerContextOps.denotNamed(Namer.scala:52)
    at dotty.tools.dotc.typer.Typer.loop$1(Typer.scala:271)
    at dotty.tools.dotc.typer.Typer.findRef$1(Typer.scala:334)
    at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:353)
    at dotty.tools.dotc.typer.Typer.typedIdent(Typer.scala:102)
    at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1658)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1726)
    at dotty.tools.dotc.typer.Typer.op$40(Typer.scala:1744)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1740)
    at dotty.tools.dotc.typer.Namer.typedAheadType$$anonfun$1(Namer.scala:961)
    at dotty.tools.dotc.typer.Namer.typedAheadImpl(Namer.scala:954)
    at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:961)
    at dotty.tools.dotc.typer.Namer.typedAheadAnnotation(Namer.scala:970)
    at dotty.tools.dotc.typer.Namer.typedAheadAnnotation(Namer.scala:969)
    at dotty.tools.dotc.typer.Namer.typedAheadAnnotation(Namer.scala:967)
    at dotty.tools.dotc.macros.package$.isAnnotMacro(macros.scala:66)
    at dotty.tools.dotc.macros.package$.hasAnnotMacros$$anonfun$1(macros.scala:59)
    at scala.collection.TraversableLike.$anonfun$filterImpl$1(TraversableLike.scala:248)
    at scala.collection.immutable.List.foreach(List.scala:389)
    at scala.collection.TraversableLike.filterImpl(TraversableLike.scala:247)
    at scala.collection.TraversableLike.filterImpl$(TraversableLike.scala:245)
    at scala.collection.AbstractTraversable.filterImpl(Traversable.scala:104)
    at scala.collection.TraversableLike.filter(TraversableLike.scala:259)
    at scala.collection.TraversableLike.filter$(TraversableLike.scala:259)
    at scala.collection.AbstractTraversable.filter(Traversable.scala:104)
    at dotty.tools.dotc.macros.package$.hasAnnotMacros(macros.scala:59)
    at dotty.tools.dotc.macros.package$.expandAnnotMacro(macros.scala:39)
    at dotty.tools.dotc.typer.Namer.expand(Namer.scala:382)
    at dotty.tools.dotc.typer.Namer.index$$anonfun$1(Namer.scala:661)
    at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
    at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
    at scala.collection.immutable.List.foreach(List.scala:389)
    at dotty.tools.dotc.typer.Namer.index(Namer.scala:661)
    at dotty.tools.dotc.typer.Namer$ClassCompleter.init(Namer.scala:853)
    at dotty.tools.dotc.typer.Namer.createSymbol(Namer.scala:293)
    at dotty.tools.dotc.typer.Namer.recur$1(Namer.scala:459)
    at dotty.tools.dotc.typer.Namer.indexExpanded(Namer.scala:469)
    at dotty.tools.dotc.typer.Namer.$anonfun$3(Namer.scala:663)
    at scala.collection.LinearSeqOptimized.foldLeft(LinearSeqOptimized.scala:122)
    at scala.collection.LinearSeqOptimized.foldLeft$(LinearSeqOptimized.scala:118)
    at scala.collection.immutable.List.foldLeft(List.scala:86)
    at scala.collection.TraversableOnce.$div$colon(TraversableOnce.scala:151)
    at scala.collection.TraversableOnce.$div$colon$(TraversableOnce.scala:151)
    at scala.collection.AbstractTraversable.$div$colon(Traversable.scala:104)
    at dotty.tools.dotc.typer.Namer.index(Namer.scala:663)
    at dotty.tools.dotc.typer.Namer.indexAndAnnotate(Namer.scala:738)
    at dotty.tools.dotc.typer.Namer$ClassCompleter.completeInCreationContext(Namer.scala:933)
    at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:780)
    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.core.SymDenotations$SymDenotation.isAbsent(SymDenotations.scala:457)
    at dotty.tools.dotc.typer.TypeAssigner.reallyExists(TypeAssigner.scala:160)
    at dotty.tools.dotc.typer.Typer.qualifies$1(Typer.scala:131)
    at dotty.tools.dotc.typer.Typer.loop$1(Typer.scala:272)
    at dotty.tools.dotc.typer.Typer.findRef$1(Typer.scala:334)
    at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:353)
    at dotty.tools.dotc.typer.Typer.typedIdent(Typer.scala:102)
    at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1658)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1726)
    at dotty.tools.dotc.typer.Typer.op$40(Typer.scala:1744)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1740)
    at dotty.tools.dotc.typer.Typer.typedType(Typer.scala:1803)
    at dotty.tools.dotc.typer.Typer.op$33(Typer.scala:1297)
    at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:1294)
    at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1663)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1726)
    at dotty.tools.dotc.typer.Typer.op$40(Typer.scala:1744)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1740)
    at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1766)
    at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1789)
    at dotty.tools.dotc.typer.Typer.op$38(Typer.scala:1564)
    at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1551)
    at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1708)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1727)
    at dotty.tools.dotc.typer.Typer.op$40(Typer.scala:1744)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1740)
    at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1801)
    at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:64)
    at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
    at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:32)
    at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:68)
    at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:93)
    at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
    at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
    at scala.collection.immutable.List.foreach(List.scala:389)
    at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:93)
    at dotty.tools.dotc.Run.op$4(Run.scala:125)
    at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:123)
    at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
    at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
    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$2(Run.scala:136)
    at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:141)
    at scala.compat.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:143)
    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)
liufengyun commented 6 years ago

@Russoul I cannot reproduce this. Could you provide a little more information about what version of gestalt are you using?

Russoul commented 6 years ago

@liufengyun what I did(checked it again now): 1)cleaned ivy2 cache 2)git clone https://github.com/liufengyun/gestalt 3)cd gestalt 4)added

trait Addable[@specialized T]{
    def plus(a : T, b : T) : T
}

into https://github.com/liufengyun/gestalt/blob/dd96f4f7074051557a7b36bb86202058c83fb9de/macros/src/main/scala/gestalt/macros/DefMacros.scala#L4

error:

...
[info] exception occurred while typechecking /home/russoul/project/dotty-macros/gestalt/macros/src/main/scala/gestalt/macros/DefMacros.scala
[info] exception occurred while compiling /home/russoul/project/dotty-macros/gestalt/macros/src/main/scala/gestalt/macros/DefMacros.scala
java.lang.AssertionError: assertion failed: no symbol for @specialized()  T
...
Russoul commented 6 years ago

@liufengyun Have you managed to reproduce it ? Are there workarounds ?

liufengyun commented 6 years ago

@Russoul thanks for the detailed information, I was able to reproduce. It seems to be a problem with library binary version mismatch. I'll propose a fix ASAP.

liufengyun commented 6 years ago

@Russoul I've fixed a problem with the modified Dotty compiler and republished it (updated snapshot). If you clean your local repo and compile again, it should work.

Russoul commented 6 years ago

@liufengyun Cool, thanks :)

liufengyun commented 6 years ago

@Russoul You are welcome. This library is still evolving, feel free to report any more problems :)