Skip to content

Commit 450bae0

Browse files
committed
wip
1 parent e345c52 commit 450bae0

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ object Printers {
6565
// tests/run-macros/quote-matching-optimize-3 failed
6666
// tests/pos-macros/i7853 failed
6767

68-
6968
// tests/run-staging/i6281.scala failed
7069
// tests/run-staging/shonan-hmm failed
71-
// tests/run-staging/i4044b.scala failed
7270
// tests/run-staging/staged-tuples failed
7371
// tests/run-staging/staged-streams_1.scala failed
7472
// tests/run-staging/quote-nested-3.scala failed

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -331,23 +331,37 @@ class ReifyQuotes extends MacroTransform {
331331
*/
332332
private def makeHole(isTermHole: Boolean, body: Tree, splices: List[Tree], tpe: Type)(implicit ctx: Context): Hole = {
333333
val idx = embedded.addTree(body, NoSymbol)
334-
val holeType = getHoleType(isTermHole)(tpe)
335-
Hole(isTermHole, idx, splices).withType(holeType).asInstanceOf[Hole]
336-
}
337334

338-
private def getHoleType(isTermHole: Boolean)(using ctx: Context) = new TypeMap() {
339-
override def apply(tp: Type): Type = tp match
340-
case tp: TypeRef if tp.typeSymbol.isSplice =>
341-
apply(tp.dealias)
342-
case tp @ TypeRef(pre, _) if !isTermHole && pre == NoPrefix || pre.termSymbol.isLocal =>
343-
val hiBound = tp.typeSymbol.info match
344-
case info @ ClassInfo(_, _, classParents, _, _) => classParents.reduce(_ & _)
345-
case info => info.hiBound
346-
apply(hiBound)
347-
case tp @ TermRef(NoPrefix, _) =>
348-
apply(tp.widenTermRefExpr)
349-
case tp =>
350-
mapOver(tp)
335+
def getTypeHoleType(using ctx: Context) = new TypeMap() {
336+
override def apply(tp: Type): Type = tp match
337+
case tp: TypeRef if tp.typeSymbol.isSplice =>
338+
apply(tp.dealias)
339+
case tp @ TypeRef(pre, _) if pre == NoPrefix || pre.termSymbol.isLocal =>
340+
val hiBound = tp.typeSymbol.info match
341+
case info @ ClassInfo(_, _, classParents, _, _) => classParents.reduce(_ & _)
342+
case info => info.hiBound
343+
apply(hiBound)
344+
case tp @ TermRef(NoPrefix, _) =>
345+
apply(tp.widenTermRefExpr)
346+
case tp =>
347+
mapOver(tp)
348+
}
349+
350+
def getTermHoleType(using ctx: Context) = new TypeMap() {
351+
override def apply(tp: Type): Type = tp match
352+
case tp @ TypeRef(NoPrefix, _) if capturers.contains(tp.symbol) =>
353+
// reference to term with a type defined in outer quote
354+
getTypeHoleType(tp)
355+
case tp @ TermRef(NoPrefix, _) /*if capturers.contains(tp.symbol)*/ => // TODO needs the guard?
356+
// widen term refs to terms defined in outer quote
357+
apply(tp.widenTermRefExpr)
358+
case tp =>
359+
mapOver(tp)
360+
}
361+
362+
val holeType = if isTermHole then getTermHoleType(tpe) else getTypeHoleType(tpe)
363+
364+
Hole(isTermHole, idx, splices).withType(holeType).asInstanceOf[Hole]
351365
}
352366

353367
override def transform(tree: Tree)(implicit ctx: Context): Tree =

library/src/scala/quoted/util/Var.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ object Var {
3838
*/
3939
def apply[T: Type, U: Type](init: Expr[T])(body: Var[T] => Expr[U])(using qctx: QuoteContext): Expr[U] = '{
4040
var x = $init
41-
// ${
42-
// body(
43-
// new Var[T] {
44-
// def get(using qctx: QuoteContext): Expr[T] = 'x
45-
// def update(e: Expr[T])(using qctx: QuoteContext): Expr[Unit] = '{ x = $e }
46-
// }
47-
// )
48-
// }
49-
???
41+
${
42+
body(
43+
new Var[T] {
44+
def get(using qctx: QuoteContext): Expr[T] = 'x
45+
def update(e: Expr[T])(using qctx: QuoteContext): Expr[Unit] = '{ x = $e }
46+
}
47+
)
48+
}
5049
}
5150
}

0 commit comments

Comments
 (0)