Skip to content

Commit

Permalink
Merge pull request #9736 from smarter/backport-star-given
Browse files Browse the repository at this point in the history
[backport] Allow `import x.{*, given}` under -Xsource:3
  • Loading branch information
lrytz committed Aug 25, 2021
2 parents b639823 + c16fc01 commit f9acc3d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2618,7 +2618,16 @@ self =>
* }}}
*/
def importSelectors(): List[ImportSelector] = {
val selectors = inBracesOrNil(commaSeparated(importSelector()))
val selectors0 = inBracesOrNil(commaSeparated(importSelector()))

// Treat an import of `*, given` or `given, *` as if it was an import of `*`
// since the former in Scala 3 has the same semantics as the latter in Scala 2.
val selectors =
if (currentRun.isScala3 && selectors0.exists(_.name eq nme.WILDCARD))
selectors0.filterNot(sel => sel.name == nme.`given` && sel.rename == sel.name)
else
selectors0

selectors.init foreach {
case ImportSelector(nme.WILDCARD, pos, _, _) => syntaxError(pos, "Wildcard import must be in last position")
case _ => ()
Expand Down
3 changes: 3 additions & 0 deletions src/reflect/scala/reflect/internal/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@ trait StdNames {
val infix: NameType = "infix"
val open: NameType = "open"

// Scala 3 hard keywords
val `given`: NameType = "given"

// Compiler utilized names

val AnnotatedType: NameType = "AnnotatedType"
Expand Down
8 changes: 8 additions & 0 deletions test/files/pos/import-future.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ class C {
import mut.*
val ab = ArrayBuffer(1)
}

object starring {

import scala.concurrent.{*, given}, duration.{given, Duration as D, *}, ExecutionContext.Implicits.*

val f = Future(42)
val r = Await.result(f, D.Inf)
}

0 comments on commit f9acc3d

Please sign in to comment.