Skip to content

Commit 26b5080

Browse files
author
Sara Alemanno
committed
Revert "Update Macros_1.scala"
This reverts commit e6caa6f.
1 parent e6caa6f commit 26b5080

File tree

1 file changed

+92
-42
lines changed

1 file changed

+92
-42
lines changed

tests/run-macros/f-interpolator-neg/Macros_1.scala

Lines changed: 92 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,107 @@ object TestFooErrors { // Defined in tests
1414
object Macro {
1515

1616
def fooErrors(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given (reflect: Reflection): Expr[List[(Boolean, Int, Int, Int, String)]] = {
17-
// true if error, false if warning
18-
// 0 if part, 1 if arg, 2 if strCtx, 3 if args
19-
// index in the list if arg or part, -1 otherwise
20-
// offset, 0 if strCtx, args or arg
21-
// message as given
22-
val reporter = new dotty.internal.StringContextMacro.Reporter{
23-
private[this] var reported = false
24-
private[this] var oldReported = false
25-
def partError(message : String, index : Int, offset : Int) : Unit = {
26-
reported = true
27-
errors += '{ Tuple5(true, 0, $index, $offset, $message) }
28-
}
29-
def partWarning(message : String, index : Int, offset : Int) : Unit = {
30-
reported = true
31-
errors += '{ Tuple5(false, 0, $index, $offset, $message) }
32-
}
17+
(strCtxExpr, argsExpr) match {
18+
case ('{ StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) =>
19+
val errors = List.newBuilder[Expr[(Boolean, Int, Int, Int, String)]]
20+
// true if error, false if warning
21+
// 0 if part, 1 if arg, 2 if strCtx, 3 if args
22+
// index in the list if arg or part, -1 otherwise
23+
// offset, 0 if strCtx, args or arg
24+
// message as given
25+
val reporter = new dotty.internal.StringContextMacro.Reporter{
26+
private[this] var reported = false
27+
private[this] var oldReported = false
28+
def partError(message : String, index : Int, offset : Int) : Unit = {
29+
reported = true
30+
errors += '{ Tuple5(true, 0, $index, $offset, $message) }
31+
}
32+
def partWarning(message : String, index : Int, offset : Int) : Unit = {
33+
reported = true
34+
errors += '{ Tuple5(false, 0, $index, $offset, $message) }
35+
}
3336

34-
def argError(message : String, index : Int) : Unit = {
35-
reported = true
36-
errors += '{ Tuple5(true, 1, $index, 0, $message) }
37-
}
37+
def argError(message : String, index : Int) : Unit = {
38+
reported = true
39+
errors += '{ Tuple5(true, 1, $index, 0, $message) }
40+
}
3841

39-
def strCtxError(message : String) : Unit = {
40-
reported = true
41-
errors += '{ Tuple5(true, 2, -1, 0, $message) }
42-
}
43-
def argsError(message : String) : Unit = {
44-
reported = true
45-
errors += '{ Tuple5(true, 3, -1, 0, $message) }
46-
}
42+
def strCtxError(message : String) : Unit = {
43+
reported = true
44+
errors += '{ Tuple5(true, 2, -1, 0, $message) }
45+
}
46+
def argsError(message : String) : Unit = {
47+
reported = true
48+
errors += '{ Tuple5(true, 3, -1, 0, $message) }
49+
}
4750

48-
def hasReported() : Boolean = {
49-
reported
50-
}
51+
def hasReported() : Boolean = {
52+
reported
53+
}
5154

52-
def resetReported() : Unit = {
53-
oldReported = reported
54-
reported = false
55-
}
55+
def resetReported() : Unit = {
56+
oldReported = reported
57+
reported = false
58+
}
5659

57-
def restoreReported() : Unit = {
58-
reported = oldReported
59-
}
60-
}
61-
(strCtxExpr, argsExpr) match {
62-
case ('{ StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) | ('{ new StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) =>
60+
def restoreReported() : Unit = {
61+
reported = oldReported
62+
}
63+
}
64+
val partsExpr = dotty.internal.StringContextMacro.getPartsExprs(strCtxExpr)
65+
val args = dotty.internal.StringContextMacro.getArgsExprs(argsExpr)
66+
dotty.internal.StringContextMacro.interpolate(partsExpr, args, argsExpr, reporter) // Discard result
67+
errors.result().toExprOfList
68+
case ('{ new StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) =>
6369
val errors = List.newBuilder[Expr[(Boolean, Int, Int, Int, String)]]
70+
// true if error, false if warning
71+
// 0 if part, 1 if arg, 2 if strCtx, 3 if args
72+
// index in the list if arg or part, -1 otherwise
73+
// offset, 0 if strCtx, args or arg
74+
// message as given
75+
val reporter = new dotty.internal.StringContextMacro.Reporter{
76+
private[this] var reported = false
77+
private[this] var oldReported = false
78+
def partError(message : String, index : Int, offset : Int) : Unit = {
79+
reported = true
80+
errors += '{ Tuple5(true, 0, $index, $offset, $message) }
81+
}
82+
def partWarning(message : String, index : Int, offset : Int) : Unit = {
83+
reported = true
84+
errors += '{ Tuple5(false, 0, $index, $offset, $message) }
85+
}
86+
87+
def argError(message : String, index : Int) : Unit = {
88+
reported = true
89+
errors += '{ Tuple5(true, 1, $index, 0, $message) }
90+
}
91+
92+
def strCtxError(message : String) : Unit = {
93+
reported = true
94+
errors += '{ Tuple5(true, 2, -1, 0, $message) }
95+
}
96+
def argsError(message : String) : Unit = {
97+
reported = true
98+
errors += '{ Tuple5(true, 3, -1, 0, $message) }
99+
}
100+
101+
def hasReported() : Boolean = {
102+
reported
103+
}
104+
105+
def resetReported() : Unit = {
106+
oldReported = reported
107+
reported = false
108+
}
109+
110+
def restoreReported() : Unit = {
111+
reported = oldReported
112+
}
113+
}
64114
val partsExpr = dotty.internal.StringContextMacro.getPartsExprs(strCtxExpr)
65115
val args = dotty.internal.StringContextMacro.getArgsExprs(argsExpr)
66116
dotty.internal.StringContextMacro.interpolate(partsExpr, args, argsExpr, reporter) // Discard result
67117
errors.result().toExprOfList
68-
case _ => QuoteError("expected statically known StringContext")
118+
}
69119
}
70120
}

0 commit comments

Comments
 (0)