Skip to content

Commit 8af7117

Browse files
committed
Fix rebase breakage
1 parent a276f0e commit 8af7117

File tree

3 files changed

+64
-21
lines changed

3 files changed

+64
-21
lines changed

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -222,39 +222,42 @@ object PrepareInlineable {
222222
val inlineCtx = ctx
223223
inlined.updateAnnotation(LazyBodyAnnotation { _ =>
224224
implicit val ctx = inlineCtx
225-
val rawBody = treeExpr(ctx)
226-
val typedBody =
227-
if (ctx.reporter.hasErrors) rawBody
228-
else ctx.compilationUnit.inlineAccessors.makeInlineable(rawBody)
229-
checkInlineMethod(inlined, typedBody)
230-
val inlineableBody = typedBody
231-
inlining.println(i"Body to inline for $inlined: $inlineableBody")
232-
inlineableBody
225+
val initialErrorCount = ctx.reporter.errorCount
226+
var inlinedBody = treeExpr(ctx)
227+
if (ctx.reporter.errorCount == initialErrorCount) {
228+
inlinedBody = ctx.compilationUnit.inlineAccessors.makeInlineable(inlinedBody)
229+
checkInlineMethod(inlined, inlinedBody)
230+
if (ctx.reporter.errorCount != initialErrorCount)
231+
inlinedBody = EmptyTree
232+
}
233+
inlining.println(i"Body to inline for $inlined: $inlinedBody")
234+
inlinedBody
233235
})
234236
}
235237
}
236238

237239
def checkInlineMethod(inlined: Symbol, body: Tree)(implicit ctx: Context): Unit = {
240+
if (inlined.owner.isClass && inlined.owner.seesOpaques)
241+
ctx.error(em"Implementation restriction: No inline methods allowed where opaque type aliases are in scope", inlined.sourcePos)
238242
if (ctx.outer.inInlineMethod)
239243
ctx.error(ex"implementation restriction: nested inline methods are not supported", inlined.sourcePos)
240244
if (inlined.name.isUnapplyName && tupleArgs(body).isEmpty)
241245
ctx.warning(
242246
em"inline unapply method can be rewritten only if its right hand side is a tuple (e1, ..., eN)",
243247
body.sourcePos)
244-
}
248+
if (inlined.is(Macro) && !ctx.isAfterTyper) {
245249

246-
def checkInlineMacro(sym: Symbol, rhs: Tree, pos: SourcePosition)(implicit ctx: Context) =
247-
if (sym.is(Macro) && !ctx.isAfterTyper) {
248-
def isValidMacro(tree: Tree)(implicit ctx: Context): Unit = tree match {
250+
def checkMacro(tree: Tree): Unit = tree match {
249251
case Spliced(code) =>
252+
if (code.symbol.flags.is(Inline))
253+
ctx.error("Macro cannot be implemented with an `inline` method", code.sourcePos)
250254
Splicer.checkValidMacroBody(code)
251-
new PCPCheckAndHeal(freshStagingContext).transform(rhs) // Ignore output, only check PCP
252-
253-
case Block(List(stat), Literal(Constants.Constant(()))) => isValidMacro(stat)
254-
case Block(Nil, expr) => isValidMacro(expr)
255-
case Typed(expr, _) => isValidMacro(expr)
255+
new PCPCheckAndHeal(freshStagingContext).transform(body) // Ignore output, only check PCP
256+
case Block(List(stat), Literal(Constants.Constant(()))) => checkMacro(stat)
257+
case Block(Nil, expr) => checkMacro(expr)
258+
case Typed(expr, _) => checkMacro(expr)
256259
case Block(DefDef(nme.ANON_FUN, _, _, _, _) :: Nil, Closure(_, fn, _)) if fn.symbol.info.isImplicitMethod =>
257-
// TODO Suppot this pattern
260+
// TODO Support this pattern
258261
ctx.error(
259262
"""Macros using a return type of the form `foo(): given X => Y` are not yet supported.
260263
|
@@ -269,9 +272,9 @@ object PrepareInlineable {
269272
|
270273
| * The contents of the splice must call a static method
271274
| * All arguments must be quoted or inline
272-
""".stripMargin, pos)
275+
""".stripMargin, inlined.sourcePos)
273276
}
274-
isValidMacro(rhs)
277+
checkMacro(body)
275278
}
279+
}
276280
}
277-

tests/neg/GenericNumLits/Even_1.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import scala.util.FromDigits
2+
import scala.quoted._
3+
import scala.quoted.matching._
4+
5+
case class Even(n: Int)
6+
object Even {
7+
8+
private def evenFromDigits(digits: String): Even = {
9+
val intValue = FromDigits.intFromDigits(digits)
10+
if (intValue % 2 == 0) Even(intValue)
11+
else throw FromDigits.MalformedNumber(s"$digits is odd")
12+
}
13+
14+
private def evenFromDigitsImpl(digits: Expr[String]) given (ctx: QuoteContext): Expr[Even] = digits match {
15+
case Const(ds) =>
16+
val ev =
17+
try evenFromDigits(ds)
18+
catch {
19+
case ex: FromDigits.FromDigitsException =>
20+
ctx.error(ex.getMessage)
21+
Even(0)
22+
}
23+
'{Even(${ev.n.toExpr})}
24+
case _ =>
25+
'{evenFromDigits($digits)}
26+
}
27+
28+
class EvenFromDigits extends FromDigits[Even] {
29+
def fromDigits(digits: String) = evenFromDigits(digits)
30+
}
31+
32+
given as EvenFromDigits {
33+
override inline def fromDigits(digits: String) = ${
34+
evenFromDigitsImpl('digits)
35+
}
36+
}
37+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
object Test extends App {
2+
3+
val e1: Even = 1234
4+
val e2: Even = 123 // error: 123 is odd
25
val e3: Even = 123456789101111 // error: number too large
36
}

0 commit comments

Comments
 (0)