@@ -17,17 +17,18 @@ import NameKinds.WildcardParamName
1717import NameOps ._
1818import ast .{Positioned , Trees }
1919import ast .Trees ._
20+ import typer .ImportInfo
2021import StdNames ._
2122import util .Spans ._
2223import Constants ._
23- import Symbols .defn
24+ import Symbols .{ defn , NoSymbol }
2425import ScriptParsers ._
2526import Decorators ._
2627import util .Chars
2728import scala .annotation .{tailrec , switch }
2829import rewrites .Rewrites .{patch , overlapsPatch }
2930import reporting ._
30- import config .Feature .{sourceVersion , migrateTo3 , dependentEnabled }
31+ import config .Feature .{sourceVersion , migrateTo3 , dependentEnabled , symbolLiteralsEnabled }
3132import config .SourceVersion ._
3233import config .SourceVersion
3334
@@ -496,20 +497,19 @@ object Parsers {
496497 * Parameters appear in reverse order.
497498 */
498499 var placeholderParams : List [ValDef ] = Nil
500+ var languageImportContext : Context = ctx
499501
500- def checkNoEscapingPlaceholders [T ](op : => T ): T = {
502+ def checkNoEscapingPlaceholders [T ](op : => T ): T =
501503 val savedPlaceholderParams = placeholderParams
504+ val savedLanguageImportContext = languageImportContext
502505 placeholderParams = Nil
503-
504506 try op
505- finally {
506- placeholderParams match {
507+ finally
508+ placeholderParams match
507509 case vd :: _ => syntaxError(UnboundPlaceholderParameter (), vd.span)
508510 case _ =>
509- }
510511 placeholderParams = savedPlaceholderParams
511- }
512- }
512+ languageImportContext = savedLanguageImportContext
513513
514514 def isWildcard (t : Tree ): Boolean = t match {
515515 case Ident (name1) => placeholderParams.nonEmpty && name1 == placeholderParams.head.name
@@ -1197,17 +1197,19 @@ object Parsers {
11971197 in.nextToken()
11981198 Quote (t)
11991199 }
1200- else {
1201- report.errorOrMigrationWarning(
1202- em """ symbol literal ' ${in.name} is no longer supported,
1203- |use a string literal " ${in.name}" or an application Symbol(" ${in.name}") instead,
1204- |or enclose in braces '{ ${in.name}} if you want a quoted expression. """ ,
1205- in.sourcePos())
1206- if migrateTo3 then
1207- patch(source, Span (in.offset, in.offset + 1 ), " Symbol(\" " )
1208- patch(source, Span (in.charOffset - 1 ), " \" )" )
1200+ else
1201+ if ! symbolLiteralsEnabled(using languageImportContext) then
1202+ report.errorOrMigrationWarning(
1203+ em """ symbol literal ' ${in.name} is no longer supported,
1204+ |use a string literal " ${in.name}" or an application Symbol(" ${in.name}") instead,
1205+ |or enclose in braces '{ ${in.name}} if you want a quoted expression.
1206+ |For now, you can also `import language.deprecated.symbolLiterals` to accept
1207+ |the idiom, but this possibility might no longer be available in the future. """ ,
1208+ in.sourcePos())
1209+ if migrateTo3 then
1210+ patch(source, Span (in.offset, in.offset + 1 ), " Symbol(\" " )
1211+ patch(source, Span (in.charOffset - 1 ), " \" )" )
12091212 atSpan(in.skipToken()) { SymbolLit (in.strVal) }
1210- }
12111213 else if (in.token == INTERPOLATIONID ) interpolatedString(inPattern)
12121214 else {
12131215 val t = literalOf(in.token)
@@ -1629,7 +1631,7 @@ object Parsers {
16291631 typeIdent()
16301632 else
16311633 def singletonArgs (t : Tree ): Tree =
1632- if in.token == LPAREN && dependentEnabled
1634+ if in.token == LPAREN && dependentEnabled( using languageImportContext)
16331635 then singletonArgs(AppliedTypeTree (t, inParens(commaSeparated(singleton))))
16341636 else t
16351637 singletonArgs(simpleType1())
@@ -3094,7 +3096,9 @@ object Parsers {
30943096
30953097 /** Create an import node and handle source version imports */
30963098 def mkImport (outermost : Boolean = false ): ImportConstr = (tree, selectors) =>
3099+ val imp = Import (tree, selectors)
30973100 if isLanguageImport(tree) then
3101+ languageImportContext = languageImportContext.importContext(imp, NoSymbol )
30983102 for
30993103 case ImportSelector (id @ Ident (imported), EmptyTree , _) <- selectors
31003104 if allSourceVersionNames.contains(imported)
@@ -3105,7 +3109,7 @@ object Parsers {
31053109 syntaxError(i " duplicate source version import " , id.span)
31063110 else
31073111 ctx.compilationUnit.sourceVersion = Some (SourceVersion .valueOf(imported.toString))
3108- Import (tree, selectors)
3112+ imp
31093113
31103114 /** ImportExpr ::= SimpleRef {‘.’ id} ‘.’ ImportSpec
31113115 * | SimpleRef ‘as’ id
0 commit comments