Skip to content

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

Closed
@soronpo

Description

@soronpo

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.

Metadata

Metadata

Assignees

Labels

itype:bugregressionThis worked in a previous version but doesn't anymore

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions