Skip to content

Compilation fails with Scala 3 -Xcheck-macros #21

Open
@aboisvert

Description

@aboisvert

When I compile my project with Scala 3.4.2 and the -Xcheck-macros compiler option, I get an error for every Table in my domain model:

{code}
[error] -- Error: /home/boisvert/fanstake/git/monorepo/webapp/src/main/scala/fanstake/model/views/RecruitsCurrentSeason.scala:24:42
[error] 24 | extends Table[RecruitCurrentSeasonRow]
[error] | ^
[error] |Exception occurred while executing macro expansion.
[error] |scala.quoted.runtime.impl.ScopeException: Expression created in a splice was used outside of that splice.
[error] |Created in: scalasql/query/src-3/TableMacro.scala:111 at column 15
[error] |Used in: scalasql/query/src-3/TableMacro.scala:160 at column 75
[error] |Type: [T] =>> T
[error] |
[error] |
[error] |Creation stack:
[error] | scalasql/query/src-3/TableMacro.scala:111 at column 15
[error] | scalasql/query/src-3/TableMacro.scala:160 at column 75
[error] |
[error] |
[error] |Use stack:
[error] | scalasql/query/src-3/TableMacro.scala:160 at column 75
[error] |
[error] |
[error] |Hint: A common reason for this to happen is when a def that creates a '{...}
[error] | captures an outer instance of Quotes. If this def is called in a splice
[error] | it will not track the Quotes provided by that particular splice.
[error] | To fix it add a given Quotes to this def.
[error] |
[error] | at scala.quoted.runtime.impl.ScopeException$.checkInCorrectScope(ScopeException.scala:35)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$.quotedTypeToTree(PickledQuotes.scala:48)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$.$anonfun$1(PickledQuotes.scala:178)
[error] | at scala.collection.Iterator$$anon$9.next(Iterator.scala:584)
[error] | at scala.collection.mutable.Growable.addAll(Growable.scala:62)
[error] | at scala.collection.mutable.Growable.addAll$(Growable.scala:57)
[error] | at scala.collection.immutable.MapBuilderImpl.addAll(Map.scala:710)
[error] | at scala.collection.immutable.Map$.from(Map.scala:661)
[error] | at scala.collection.IterableOnceOps.toMap(IterableOnce.scala:1320)
[error] | at scala.collection.IterableOnceOps.toMap$(IterableOnce.scala:1319)
[error] | at scala.collection.AbstractIterator.toMap(Iterator.scala:1300)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$.spliceTypes(PickledQuotes.scala:180)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTypeTree(PickledQuotes.scala:97)
[error] | at scala.quoted.runtime.impl.QuotesImpl.unpickleTypeV2(QuotesImpl.scala:3228)
[error] | at scalasql.query.TableMacros$.constructV$1(TableMacro.scala:42)
[error] | at scalasql.query.TableMacros$.$anonfun$3$$anonfun$2(TableMacro.scala:113)
[error] | at scalasql.query.TableMacros$.$anonfun$3(TableMacro.scala:107)
[error] | at scalasql.query.TableMacros$.$anonfun$adapted$3(TableMacro.scala:123)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:111)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1568)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1600)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
[error] | at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1254)
[error] | at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1254)
[error] | at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1259)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1548)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1544)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1640)
[error] | at scala.collection.immutable.List.mapConserve(List.scala:472)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1640)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1534)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
[error] | at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock$$anonfun$1$$anonfun$1(tpd.scala:1259)
[error] | at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1241)
[error] | at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1254)
[error] | at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1259)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1548)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1600)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
[error] | at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1254)
[error] | at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1254)
[error] | at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1259)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1548)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$.spliceTerms(PickledQuotes.scala:153)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTerm(PickledQuotes.scala:89)
[error] | at scala.quoted.runtime.impl.QuotesImpl.unpickleExprV2(QuotesImpl.scala:3220)
[error] | at scalasql.query.TableMacros$.applyImpl(TableMacro.scala:123)
[error] |
[error] |---------------------------------------------------------------------------
[error] |Inline stack trace
[error] |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error] |This location contains code that was inlined from TableMacro.scala:160
[error] ---------------------------------------------------------------------------
{code}

Without this compiler option, everything works fine. However, I want to compile with -Xcheck-macros to debug some other macro issue (unrelated to scalasql).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions