Skip to content

Commit f9acc3d

Browse files
authored
Merge pull request scala#9736 from smarter/backport-star-given
[backport] Allow `import x.{*, given}` under -Xsource:3
2 parents b639823 + c16fc01 commit f9acc3d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

+10-1
Original file line numberDiff line numberDiff line change
@@ -2618,7 +2618,16 @@ self =>
26182618
* }}}
26192619
*/
26202620
def importSelectors(): List[ImportSelector] = {
2621-
val selectors = inBracesOrNil(commaSeparated(importSelector()))
2621+
val selectors0 = inBracesOrNil(commaSeparated(importSelector()))
2622+
2623+
// Treat an import of `*, given` or `given, *` as if it was an import of `*`
2624+
// since the former in Scala 3 has the same semantics as the latter in Scala 2.
2625+
val selectors =
2626+
if (currentRun.isScala3 && selectors0.exists(_.name eq nme.WILDCARD))
2627+
selectors0.filterNot(sel => sel.name == nme.`given` && sel.rename == sel.name)
2628+
else
2629+
selectors0
2630+
26222631
selectors.init foreach {
26232632
case ImportSelector(nme.WILDCARD, pos, _, _) => syntaxError(pos, "Wildcard import must be in last position")
26242633
case _ => ()

src/reflect/scala/reflect/internal/StdNames.scala

+3
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ trait StdNames {
640640
val infix: NameType = "infix"
641641
val open: NameType = "open"
642642

643+
// Scala 3 hard keywords
644+
val `given`: NameType = "given"
645+
643646
// Compiler utilized names
644647

645648
val AnnotatedType: NameType = "AnnotatedType"

test/files/pos/import-future.scala

+8
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ class C {
2323
import mut.*
2424
val ab = ArrayBuffer(1)
2525
}
26+
27+
object starring {
28+
29+
import scala.concurrent.{*, given}, duration.{given, Duration as D, *}, ExecutionContext.Implicits.*
30+
31+
val f = Future(42)
32+
val r = Await.result(f, D.Inf)
33+
}

0 commit comments

Comments
 (0)