Skip to content

Commit 9ea5107

Browse files
committed
Move type quote and splice error to parser
1 parent ccdeb85 commit 9ea5107

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,13 +1574,17 @@ object Parsers {
15741574
/** The block in a quote or splice */
15751575
def stagedBlock() = inBraces(block(simplify = true))
15761576

1577-
/** SimpleExpr ::= spliceId | ‘$’ ‘{’ Block ‘}’) unless inside quoted pattern
1578-
* SimpleType ::= spliceId | ‘$’ ‘{’ Block ‘}’) unless inside quoted pattern
1577+
/** ExprSplice ::= ‘$’ spliceId if inside quoted block
1578+
* | ‘$’ ‘{’ Block ‘}’) unless inside quoted pattern
1579+
* | ‘$’ ‘{’ Pattern ‘}’) when inside quoted pattern
15791580
*
1580-
* SimpleExpr ::= spliceId | ‘$’ ‘{’ Pattern ‘}’) when inside quoted pattern
1581-
* SimpleType ::= spliceId | ‘$’ ‘{’ Pattern ‘}’) when inside quoted pattern
1581+
* // Deprecated syntax
1582+
* TypeSplice ::= ‘$’ spliceId if inside quoted type
1583+
* | ‘$’ ‘{’ Block ‘}’) unless inside quoted pattern
1584+
* | ‘$’ ‘{’ Pattern ‘}’) when inside quoted pattern
15821585
*/
15831586
def splice(isType: Boolean): Tree =
1587+
val start = in.offset
15841588
atSpan(in.offset) {
15851589
val expr =
15861590
if (in.name.length == 1) {
@@ -1593,7 +1597,16 @@ object Parsers {
15931597
in.nextToken()
15941598
id
15951599
}
1596-
if (isType) TypSplice(expr) else Splice(expr)
1600+
if isType then
1601+
val msg = "Type splicing with `$` in quotes not supported anymore"
1602+
val inPattern = (staged & StageKind.QuotedPattern) != 0
1603+
val hint =
1604+
if inPattern then "Use lower cased variable name without the `$` instead"
1605+
else "Use a given Type[T] in a quote just write T directly"
1606+
syntaxError(s"$msg\n\nHint: $hint", Span(start, in.lastOffset))
1607+
Ident(nme.ERROR.toTypeName)
1608+
else
1609+
Splice(expr)
15971610
}
15981611

15991612
/** SimpleType ::= SimpleLiteral
@@ -1637,7 +1650,7 @@ object Parsers {
16371650
* | Singleton `.' type
16381651
* | ‘(’ ArgTypes ‘)’
16391652
* | Refinement
1640-
* | ‘$’ ‘{’ Block ‘}’
1653+
* | TypeSplice
16411654
* | SimpleType1 TypeArgs
16421655
* | SimpleType1 `#' id
16431656
*/
@@ -2239,7 +2252,7 @@ object Parsers {
22392252
/** SimpleExpr ::= ‘new’ ConstrApp {`with` ConstrApp} [TemplateBody]
22402253
* | ‘new’ TemplateBody
22412254
* | BlockExpr
2242-
* | ‘$’ ‘{’ Block ‘}’
2255+
* | ExprSplice
22432256
* | Quoted
22442257
* | quoteId
22452258
* | SimpleExpr1 [`_`]

0 commit comments

Comments
 (0)