Skip to content
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

opaque type regression in nightly causes type mismatch by missing an extension method #13021

Closed
soronpo opened this issue Jul 6, 2021 · 6 comments · Fixed by #20104
Closed
Assignees
Labels
itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@soronpo
Copy link
Contributor

soronpo commented Jul 6, 2021

Compilation order seems to affect the ability to use an extension method on an opaque type that has an underlying value in the same name (data in this case). The features interacting here are opaque types, extension methods, transparent inline macros, and incremental compilation. I believe the transparent inline macro is just affecting the compilation order and has nothing to do with the actual bug here.

Compiler version

Error in 3.0.2-RC1-bin-20210701-9f97b0b-NIGHTLY
v3.0.1-RC2 is OK!
The regression may be in the inline and opaque type changes, but I have not bisected it (not possible to do on my machine).

Minimized code

Minimized project at: https://github.com/soronpo/dottybug/tree/opaque_fail

Width.scala

import scala.quoted.*

trait Width[T]:
  type Out <: Int
object Width:
  transparent inline given [T]: Width[T] = ${ getWidthMacro[T] }
  def getWidthMacro[T](using Quotes, Type[T]): Expr[Width[T]] =
    '{
      new Width[T] {
        type Out = Int
      }
    }

DFToken.scala

trait Token:
  val data: Any

opaque type DFToken = Token
object DFToken:
  extension (of: DFToken) def asIR: Token = ???

  opaque type Of[D] <: DFToken = DFToken
  object Of:
    extension [D](token: Of[D]) def width(using w: Width[_]): Int = ???

def getWidth[W <: Int](token: DFBits.Token[W]): Int = token.width
def getData[W <: Int](token: DFBits.Token[W]): Int =
  token.data //error here

DFBits.scala

object DFBits:
  opaque type Token[W <: Int] <: DFToken.Of[Int] = DFToken.Of[Int]
  extension [W <: Int](token: Token[W])
    def data: Int =
      token.asIR
      1

Output

[error] -- [E007] Type Mismatch Error: C:\IdeaProjects\dottybug\src\main\scala\DFToken.scala:14:8 ---------------------------
[error] 14 |  token.data //error here
[error]    |  ^^^^^^^^^^
[error]    |  Found:    (token.data : Any)
[error]    |  Required: Int
[error] one error found

Expectation

No error.

@soronpo
Copy link
Contributor Author

soronpo commented Jul 6, 2021

Note: some things appear unrelated here, but if you remove them the error disappears. This is the most minimized version I managed to make.

@soronpo soronpo added the regression This worked in a previous version but doesn't anymore label Jul 6, 2021
@odersky
Copy link
Contributor

odersky commented Jul 6, 2021

Can we find out which commit causes the regression?

@soronpo
Copy link
Contributor Author

soronpo commented Jul 6, 2021

Unfortunately, on my machine I can barely compile Scala3, so I'm unable to bisect it.

@griggt
Copy link
Contributor

griggt commented Jul 6, 2021

Can we find out which commit causes the regression?

It seems the error as reported began with #12815, however the example fails to compile beginning with #12541, giving the following stack trace:

assertion failure for DFBits.type <:< ?{ Token: ? }, frozen = false
exception occurred while typechecking DFToken.scala
java.lang.AssertionError: NoDenotation.owner while compiling DFBits.scala, DFToken.scala, Width.scala
Exception in thread "main" java.lang.AssertionError: NoDenotation.owner
	at dotty.tools.dotc.core.SymDenotations$NoDenotation$.owner(SymDenotations.scala:2428)
	at dotty.tools.dotc.core.SymDenotations$.stillValidInOwner(SymDenotations.scala:2489)
	at dotty.tools.dotc.core.SymDenotations$.stillValidInOwner(SymDenotations.scala:2496)
	at dotty.tools.dotc.core.SymDenotations$.stillValid(SymDenotations.scala:2485)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:744)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.toNewRun$1(Denotations.scala:803)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:877)
	at dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:122)
	at dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:116)
	at dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:109)
	at dotty.tools.dotc.core.SymDenotations$.stillValidInOwner(SymDenotations.scala:2489)
	at dotty.tools.dotc.core.SymDenotations$.stillValid(SymDenotations.scala:2485)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:744)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.toNewRun$1(Denotations.scala:803)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:877)
	at dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:122)
	at dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:116)
	at dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:109)
	at dotty.tools.dotc.core.SymDenotations$.stillValidInOwner(SymDenotations.scala:2489)
	at dotty.tools.dotc.core.SymDenotations$.stillValid(SymDenotations.scala:2483)
	at dotty.tools.dotc.core.Symbols$Symbol.isValidInCurrentRun(Symbols.scala:151)
	at dotty.tools.dotc.core.Types$NamedType.computeSymbol(Types.scala:2123)
	at dotty.tools.dotc.core.Types$NamedType.symbol(Types.scala:2118)
	at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:99)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5281)
	at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:109)
	at dotty.tools.dotc.core.Types$TypeMap.mapOverLambda(Types.scala:5259)
	at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:103)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5293)
	at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:109)
	at dotty.tools.dotc.core.TypeOps$.asSeenFrom(TypeOps.scala:54)
	at dotty.tools.dotc.core.Types$Type.asSeenFrom(Types.scala:1024)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.derived$1(Denotations.scala:1096)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1118)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1076)
	at dotty.tools.dotc.core.Denotations$PreDenotation.asSeenFrom(Denotations.scala:135)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:1992)
	at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:683)
	at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:870)
	at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:666)
	at dotty.tools.dotc.core.Types$Type.member(Types.scala:650)
	at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.isMatchedBy(ProtoTypes.scala:198)
	at dotty.tools.dotc.core.TypeComparer.isMatchedByProto(TypeComparer.scala:1856)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:305)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1282)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:185)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:195)
	at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:128)
	at dotty.tools.dotc.core.TypeComparer.testSubType(TypeComparer.scala:144)
	at dotty.tools.dotc.core.TypeComparer$.testSubType(TypeComparer.scala:2688)
	at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$4(Typer.scala:3524)
	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3620)
	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3811)
	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3163)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2943)
	at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:609)
	at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:659)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2665)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2757)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Typer.typedAppliedTypeTree(Typer.scala:1862)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2721)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2758)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Namer.typedAheadType$$anonfun$1(Namer.scala:1389)
	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1381)
	at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:1389)
	at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1635)
	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:699)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:826)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:727)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:167)
	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:369)
	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2637)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2662)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2757)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1394)
	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1381)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1394)
	at dotty.tools.dotc.typer.Namer.completeParams$$anonfun$1(Namer.scala:1410)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.typer.Namer.completeParams(Namer.scala:1410)
	at dotty.tools.dotc.typer.Namer.defDefSig$$anonfun$3(Namer.scala:1673)
	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.Namer.defDefSig(Namer.scala:1673)
	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:703)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:826)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:727)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:167)
	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:369)
	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2637)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2662)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2757)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2849)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2899)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2354)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2683)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2687)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2757)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2849)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2899)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2477)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2728)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2758)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2943)
	at dotty.tools.dotc.typer.FrontEnd.liftedTree1$1(FrontEnd.scala:79)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:84)
	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:43)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:85)
	at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:120)
	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.FrontEnd.runOn(FrontEnd.scala:120)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:205)
	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$5(Run.scala:216)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:224)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:231)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:172)
	at dotty.tools.dotc.Driver.finish(Driver.scala:60)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:40)
	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)

@odersky
Copy link
Contributor

odersky commented Jul 8, 2021

Thanks for the bisecting, @griggt! Maybe Jamie could take a look at it then? I am not sure it's related to #12541 but it's probably as good a place to start the search as any.

@anatoliykmetyuk anatoliykmetyuk added this to the 3.1.3 milestone May 30, 2022
@odersky odersky removed this from the 3.1.3 milestone May 31, 2022
@bishabosha
Copy link
Member

bishabosha commented Apr 5, 2024

this compiles in 3.2.0, 3.3.3, 3.4.0, 3.4.2-RC1

I'll add a regression test

bishabosha added a commit to dotty-staging/dotty that referenced this issue Apr 5, 2024
nicolasstucki added a commit that referenced this issue Apr 9, 2024
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
WojciechMazur pushed a commit that referenced this issue Jul 5, 2024
WojciechMazur added a commit that referenced this issue Jul 5, 2024
Backports #20104 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants