Skip to content

Commit

Permalink
Merge pull request scala#12515 from dotty-staging/fix-#12510
Browse files Browse the repository at this point in the history
Synthesize `ValueOf[Unit]` for a name designator
  • Loading branch information
nicolasstucki authored May 27, 2021
2 parents feabdf0 + c4e7259 commit 7b9ea5c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/typer/Synthesizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,12 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):

def success(t: Tree) =
New(defn.ValueOfClass.typeRef.appliedTo(t.tpe), t :: Nil).withSpan(span)

formal.argInfos match
case arg :: Nil =>
fullyDefinedType(arg.dealias, "ValueOf argument", span).normalized match
case ConstantType(c: Constant) =>
success(Literal(c))
case TypeRef(_, sym) if sym == defn.UnitClass =>
case tp: TypeRef if tp.isRef(defn.UnitClass) =>
success(Literal(Constant(())))
case n: TermRef =>
success(ref(n))
Expand Down
11 changes: 11 additions & 0 deletions tests/pos-macros/i12510/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
object M {
import scala.quoted.*

inline def valueOfUnit: ValueOf[Unit] =
${ _valueOfUnit }

def _valueOfUnit(using Quotes): Expr[ValueOf[Unit]] = {
import quotes.reflect.*
Expr.summon[ValueOf[Unit]] getOrElse sys.error("Not found")
}
}
4 changes: 4 additions & 0 deletions tests/pos-macros/i12510/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object T {
val ok = summon[ValueOf[Unit]]
val ko = M.valueOfUnit
}

0 comments on commit 7b9ea5c

Please sign in to comment.