From 93674c5722e53316791dcba46b2caa69c81c83e7 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Fri, 5 Apr 2024 16:15:14 +0200 Subject: [PATCH] add regression test for issue #13021 --- tests/pos-macros/i13021/DFBits.scala | 6 ++++++ tests/pos-macros/i13021/DFToken.scala | 14 ++++++++++++++ tests/pos-macros/i13021/Width.scala | 12 ++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/pos-macros/i13021/DFBits.scala create mode 100644 tests/pos-macros/i13021/DFToken.scala create mode 100644 tests/pos-macros/i13021/Width.scala diff --git a/tests/pos-macros/i13021/DFBits.scala b/tests/pos-macros/i13021/DFBits.scala new file mode 100644 index 000000000000..0ab76f1687ac --- /dev/null +++ b/tests/pos-macros/i13021/DFBits.scala @@ -0,0 +1,6 @@ +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 diff --git a/tests/pos-macros/i13021/DFToken.scala b/tests/pos-macros/i13021/DFToken.scala new file mode 100644 index 000000000000..ce8e2f11b733 --- /dev/null +++ b/tests/pos-macros/i13021/DFToken.scala @@ -0,0 +1,14 @@ +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 diff --git a/tests/pos-macros/i13021/Width.scala b/tests/pos-macros/i13021/Width.scala new file mode 100644 index 000000000000..a163e1b5ebf1 --- /dev/null +++ b/tests/pos-macros/i13021/Width.scala @@ -0,0 +1,12 @@ +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 + } + }