Skip to content

Unresolved symbol in quoted class with spliced field reference #7997

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
nicolasstucki opened this issue Jan 15, 2020 · 0 comments · Fixed by #8796
Closed

Unresolved symbol in quoted class with spliced field reference #7997

nicolasstucki opened this issue Jan 15, 2020 · 0 comments · Fixed by #8796

Comments

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Jan 15, 2020

minimized code

import scala.quoted._
def oops(using QuoteContext) = {
  val q = '{ class Foo { val x = 3; ${ val v = 'x; '{} }  }}
}
Compilation output
java.lang.AssertionError: assertion failed: unresolved symbols: class Foo(line 3) when pickling Foo.scala while compiling Foo.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: unresolved symbols: class Foo(line 3) when pickling Foo.scala
        at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
        at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:704)
        at dotty.tools.dotc.core.quoted.PickledQuotes$.pickle(PickledQuotes.scala:102)
        at dotty.tools.dotc.core.quoted.PickledQuotes$.pickleQuote(PickledQuotes.scala:34)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.pickleAsTasty$1(ReifyQuotes.scala:236)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.pickledQuote(ReifyQuotes.scala:248)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transformQuotation(ReifyQuotes.scala:196)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:93)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1251)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:117)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1257)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:117)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1320)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:101)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1347)
        at scala.collection.immutable.List.mapConserve(List.scala:444)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1347)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1345)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1271)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:89)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:105)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:97)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1347)
        at scala.collection.immutable.List.mapConserve(List.scala:444)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1347)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1345)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1271)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:89)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:105)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transformWithCapturer(ReifyQuotes.scala:355)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.body$3(ReifyQuotes.scala:329)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.$anonfun$1(ReifyQuotes.scala:339)
        at dotty.tools.dotc.ast.tpd$.polyDefDef(tpd.scala:262)
        at dotty.tools.dotc.ast.tpd$.DefDef(tpd.scala:221)
        at dotty.tools.dotc.ast.tpd$.Closure(tpd.scala:115)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.makeLambda(ReifyQuotes.scala:339)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.splitSplice(ReifyQuotes.scala:376)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transformSplice(ReifyQuotes.scala:266)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:99)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:51)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:58)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:108)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:413)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1327)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:101)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:413)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1347)
        at scala.collection.immutable.List.mapConserve(List.scala:444)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1347)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1345)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1271)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:89)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:105)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.splitQuote(ReifyQuotes.scala:371)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transformQuotation(ReifyQuotes.scala:191)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:93)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1251)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:117)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1257)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:117)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1320)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:101)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1347)
        at scala.collection.immutable.List.mapConserve(List.scala:444)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1347)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1345)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1271)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:89)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:105)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:97)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:51)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:58)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:108)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1327)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:101)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1347)
        at scala.collection.immutable.List.mapConserve(List.scala:444)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1347)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1345)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1333)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:101)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
        at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:415)
        at dotty.tools.dotc.transform.ReifyQuotes$$anon$1.transform(ReifyQuotes.scala:93)
        at dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:21)
        at dotty.tools.dotc.transform.ReifyQuotes.run(ReifyQuotes.scala:89)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:315)
        at scala.collection.immutable.List.map(List.scala:219)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:316)
        at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:167)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$5(Run.scala:177)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:185)
        at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:65)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:192)
        at dotty.tools.dotc.Run.compileSources(Run.scala:129)
        at dotty.tools.dotc.Run.compile(Run.scala:112)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:36)
        at dotty.tools.dotc.Driver.process(Driver.scala:189)
        at dotty.tools.dotc.Driver.process(Driver.scala:158)
        at dotty.tools.dotc.Driver.process(Driver.scala:170)
        at dotty.tools.dotc.Driver.main(Driver.scala:197)
        at dotty.tools.dotc.Main.main(Main.scala)

expectation

Should compile

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 29, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 29, 2020
Fix scala#6140, fix scala#6772, fix scala#7030, fix scala#7892, fix scala#7997, fix scala#8651 and improve scala#8100.

Differences with previous implementation
* Only track and check levels within quotes or splices
* Track levels of all symbols not at level 0
* Split level checking into specialized variants for types and terms (healType/healTermType)
* Detect inconsistent types rather than try to detect consistent ones
* Check/heal term inconsistencies only on leaf nodes (TypeTree, RefTree, Ident, This)
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 4, 2020
Fix scala#6140, fix scala#6772, fix scala#7030, fix scala#7892, fix scala#7997, fix scala#8651 and improve scala#8100.

Differences with previous implementation
* Only track and check levels within quotes or splices
* Track levels of all symbols not at level 0
* Split level checking into specialized variants for types and terms (healType/healTermType)
* Detect inconsistent types rather than try to detect consistent ones
* Check/heal term inconsistencies only on leaf nodes (TypeTree, RefTree, Ident, This)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant