-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Weird Case Class Compiler Error with Inline Function #12508
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
Comments
Minimizes slightly class Test {
inline def test(fun: Any): Any = ???
test {
case class Foo[X](x: X)
}
} |
Note that this is a regression introduced between 3.0.0-RC1 and 3.0.0-RC2. |
Apply workarounds for scala/scala3#12508
@nicolasstucki @TomasMikula Fyi I updated the example project to use Scala 3.0.1 but unfortunately it still encounters the same problem. |
@nicolasstucki @TomasMikula Fyi I updated the example project to use Scala 3.0.2-RC1, but unfortunately it still encounters the same problem:
|
@nicolasstucki @TomasMikula Fyi I updated the example project to use Scala 3.0.2 but unfortunately it still encounters the same problem. The example project is at: https://github.com/cheeseng/scala3-case-class-inline-problem |
@nicolasstucki @TomasMikula Fyi I updated the example project to use Scala 3.1.0 but unfortunately it still encounters the same problem: The example project is at: https://github.com/cheeseng/scala3-case-class-inline-problem |
Minimized further to class Test {
inline def test(fun: Any): Any = ???
test {
class Foo[X]:
def x: X = ???
def foo: Unit = this.x.toString
}
} |
This regression is quite a blocker for us. Any idea if it'll be resolved soon? |
It looks like the bug was introduced in 0241150 |
{
class Foo[X]:
def x: X = ???
def foo: Unit = this.x.toString
()
} Stack trace
|
It seems this is a more general issue that is not only present when inlining. Here is another way to trigger the same failure in def fun(a: Any, b: Any = 2): Any = ???
def test =
fun(
b = println(1),
a = {
class Foo[X]:
def x: X = ???
def foo: Unit = this.x.toString
}
) Stack tracedotty.tools.dotc.core.TypeError: bad parameter reference Foo.this.X at typer
the parameter is type X in class Foo but the prefix (Foo.this : Foo[X])
does not define any corresponding arguments.
idx = 0, args = List()
at dotty.tools.dotc.core.Types$NamedType.argDenot(Types.scala:2327)
at dotty.tools.dotc.core.Types$NamedType.fromDesignator$1(Types.scala:2240)
at dotty.tools.dotc.core.Types$NamedType.computeDenot(Types.scala:2258)
at dotty.tools.dotc.core.Types$NamedType.denot(Types.scala:2213)
at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:685)
at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:878)
at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:669)
at dotty.tools.dotc.core.Types$Type.nonPrivateMember(Types.scala:659)
at dotty.tools.dotc.core.Types$NamedType.memberDenot(Types.scala:2291)
at dotty.tools.dotc.core.Types$NamedType.reload$1(Types.scala:2575)
at dotty.tools.dotc.core.Types$NamedType.withPrefix(Types.scala:2588)
at dotty.tools.dotc.core.Types$NamedType.derivedSelect(Types.scala:2528)
at dotty.tools.dotc.ast.tpd$TypedTreeCopier.Select(tpd.scala:602)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1383)
at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:141)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1389)
at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:141)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1493)
at scala.collection.immutable.List.mapConserve(List.scala:472)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1493)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformSub(Trees.scala:1497)
at dotty.tools.dotc.ast.TreeTypeMap.transformDefs(TreeTypeMap.scala:150)
at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:120)
at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:109)
at dotty.tools.dotc.ast.TreeTypeMap.$anonfun$2(TreeTypeMap.scala:101)
at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:92)
at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:108)
at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:101)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1466)
at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:141)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1493)
at scala.collection.immutable.List.mapConserve(List.scala:472)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1493)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformSub(Trees.scala:1497)
at dotty.tools.dotc.ast.TreeTypeMap.transformDefs(TreeTypeMap.scala:150)
at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:120)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1457)
at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:141)
at dotty.tools.dotc.ast.TreeTypeMap.apply(TreeTypeMap.scala:163)
at dotty.tools.dotc.ast.tpd$TreeOps$.changeNonLocalOwners$extension(tpd.scala:839)
at dotty.tools.dotc.typer.Lifter.lift(EtaExpansion.scala:56)
at dotty.tools.dotc.typer.Lifter.liftArg(EtaExpansion.scala:80)
at dotty.tools.dotc.typer.Lifter.liftArgs$$anonfun$1(EtaExpansion.scala:94)
at scala.collection.LazyZip3$$anon$9$$anon$10.next(LazyZipOps.scala:171)
at scala.collection.immutable.List.prependedAll(List.scala:153)
at scala.collection.immutable.List$.from(List.scala:684)
at scala.collection.immutable.List$.from(List.scala:681)
at scala.collection.BuildFromLowPriority2$$anon$11.fromSpecific(BuildFrom.scala:112)
at scala.collection.BuildFromLowPriority2$$anon$11.fromSpecific(BuildFrom.scala:109)
at scala.collection.LazyZip3.map(LazyZipOps.scala:165)
at dotty.tools.dotc.typer.Lifter.liftArgs(EtaExpansion.scala:95)
at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:816)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:852)
at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1051)
at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:317)
at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:119)
at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:898)
at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$3(Applications.scala:977)
at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3074)
at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:988)
at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1026)
at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:317)
at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:119)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2802)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2865)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2930)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2934)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3050)
at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1473)
at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1463)
at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1473)
at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1710)
at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:238)
at dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:1710)
at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1718)
at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1736)
at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1737)
at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1748)
at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1512)
at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1519)
at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1588)
at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:782)
at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:914)
at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:806)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:168)
at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:188)
at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:190)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:370)
at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2744)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2769)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2864)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2930)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2934)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2956)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3006)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2447)
at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2790)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2794)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2864)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2930)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2934)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2956)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3006)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2574)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2835)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2865)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2930)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2934)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3050)
at dotty.tools.dotc.typer.TyperPhase.liftedTree1$1(TyperPhase.scala:47)
at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:53)
at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:411)
at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54)
at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.immutable.List.foreach(List.scala:333)
at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88)
at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:259)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
at dotty.tools.dotc.Run.runPhases$1(Run.scala:270)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:278)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
at dotty.tools.dotc.Run.compileUnits(Run.scala:287)
at dotty.tools.dotc.Run.compileSources(Run.scala:220)
at dotty.tools.dotc.Run.compile(Run.scala:204)
at dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
at dotty.tools.dotc.Driver.process(Driver.scala:199)
at dotty.tools.dotc.Driver.process(Driver.scala:167)
at dotty.tools.dotc.Driver.process(Driver.scala:179)
at dotty.tools.dotc.Driver.main(Driver.scala:209)
at dotty.tools.dotc.Main.main(Main.scala) |
The issue is probably located in the |
@odersky could you have a look at this issue? |
…since boundSym is new, no need to use check in QuoteUtils.changeOwner)" This reverts commit 0241150 This might help fix scala#12508
Fix TreeTypeMap to correctly substitute parameters when copying local class members. Fixes scala#12508
Thanks for fixing this! |
@odersky @nicolasstucki May I know if this fix is included in 3.1.2? I updated the example project to use Scala 3.1.2 and but still encounters the same error: https://github.com/cheeseng/scala3-case-class-inline-problem |
@cheeseng It should be in 3.1.3, which is about to be released. It is in 3.1.3 RC2. |
@odersky I just tested it with 3.1.3-RC2, and it works! Thanks! |
Uh oh!
There was an error while loading. Please reload this page.
Compiler version
Scala Version: 3.0.0 - 3.0.2
SBT: 1.5.2, 1.5.5
Example project here: https://github.com/cheeseng/scala3-case-class-inline-problem
Minimized code
Output
Expectation
The code should compile without error.
The text was updated successfully, but these errors were encountered: