Skip to content

Commit 91f352d

Browse files
committed
Recognize language imports during parsing
1 parent ce30a1c commit 91f352d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ import NameKinds.WildcardParamName
1717
import NameOps._
1818
import ast.{Positioned, Trees}
1919
import ast.Trees._
20+
import typer.ImportInfo
2021
import StdNames._
2122
import util.Spans._
2223
import Constants._
23-
import Symbols.defn
24+
import Symbols.{defn, NoSymbol}
2425
import ScriptParsers._
2526
import Decorators._
2627
import util.Chars
@@ -492,20 +493,19 @@ object Parsers {
492493
* Parameters appear in reverse order.
493494
*/
494495
var placeholderParams: List[ValDef] = Nil
496+
var languageImportContext: Context = ctx
495497

496-
def checkNoEscapingPlaceholders[T](op: => T): T = {
498+
def checkNoEscapingPlaceholders[T](op: => T): T =
497499
val savedPlaceholderParams = placeholderParams
500+
val savedLanguageImportContext = languageImportContext
498501
placeholderParams = Nil
499-
500502
try op
501-
finally {
502-
placeholderParams match {
503+
finally
504+
placeholderParams match
503505
case vd :: _ => syntaxError(UnboundPlaceholderParameter(), vd.span)
504506
case _ =>
505-
}
506507
placeholderParams = savedPlaceholderParams
507-
}
508-
}
508+
languageImportContext = savedLanguageImportContext
509509

510510
def isWildcard(t: Tree): Boolean = t match {
511511
case Ident(name1) => placeholderParams.nonEmpty && name1 == placeholderParams.head.name
@@ -1625,7 +1625,7 @@ object Parsers {
16251625
typeIdent()
16261626
else
16271627
def singletonArgs(t: Tree): Tree =
1628-
if in.token == LPAREN && dependentEnabled
1628+
if in.token == LPAREN && dependentEnabled(using languageImportContext)
16291629
then singletonArgs(AppliedTypeTree(t, inParens(commaSeparated(singleton))))
16301630
else t
16311631
singletonArgs(simpleType1())
@@ -3090,7 +3090,9 @@ object Parsers {
30903090

30913091
/** Create an import node and handle source version imports */
30923092
def mkImport(outermost: Boolean = false): ImportConstr = (tree, selectors) =>
3093+
val imp = Import(tree, selectors)
30933094
if isLanguageImport(tree) then
3095+
languageImportContext = languageImportContext.importContext(imp, NoSymbol)
30943096
for
30953097
case ImportSelector(id @ Ident(imported), EmptyTree, _) <- selectors
30963098
if allSourceVersionNames.contains(imported)
@@ -3101,7 +3103,7 @@ object Parsers {
31013103
syntaxError(i"duplicate source version import", id.span)
31023104
else
31033105
ctx.compilationUnit.sourceVersion = Some(SourceVersion.valueOf(imported.toString))
3104-
Import(tree, selectors)
3106+
imp
31053107

31063108
/** ImportExpr ::= SimpleRef {‘.’ id} ‘.’ ImportSpec
31073109
* | SimpleRef ‘as’ id

0 commit comments

Comments
 (0)