Skip to content

Commit c4e7259

Browse files
committed
Synthesize ValueOf[Unit] for a name designator
Fixes #12510
1 parent 4bf2f04 commit c4e7259

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,12 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
160160

161161
def success(t: Tree) =
162162
New(defn.ValueOfClass.typeRef.appliedTo(t.tpe), t :: Nil).withSpan(span)
163-
164163
formal.argInfos match
165164
case arg :: Nil =>
166165
fullyDefinedType(arg.dealias, "ValueOf argument", span).normalized match
167166
case ConstantType(c: Constant) =>
168167
success(Literal(c))
169-
case TypeRef(_, sym) if sym == defn.UnitClass =>
168+
case tp: TypeRef if tp.isRef(defn.UnitClass) =>
170169
success(Literal(Constant(())))
171170
case n: TermRef =>
172171
success(ref(n))

tests/pos-macros/i12510/Macro_1.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object M {
2+
import scala.quoted.*
3+
4+
inline def valueOfUnit: ValueOf[Unit] =
5+
${ _valueOfUnit }
6+
7+
def _valueOfUnit(using Quotes): Expr[ValueOf[Unit]] = {
8+
import quotes.reflect.*
9+
Expr.summon[ValueOf[Unit]] getOrElse sys.error("Not found")
10+
}
11+
}

tests/pos-macros/i12510/Test_2.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object T {
2+
val ok = summon[ValueOf[Unit]]
3+
val ko = M.valueOfUnit
4+
}

0 commit comments

Comments
 (0)