Skip to content

Commit 8b8a7ff

Browse files
committed
Imlement new import seclectors for givens
It's now ```scala given _ given T ``` Thta way it's more regular: A given selector is always followed by something: Either a wildcard or a type. The previous syntax for type bounds on normal imports is no longer supported. We might want to bring it back at some point, but it's not essential.
1 parent 0e2a86a commit 8b8a7ff

File tree

168 files changed

+256
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+256
-257
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,7 +2985,6 @@ object Parsers {
29852985
/** ImportExpr ::= StableId ‘.’ ImportSpec
29862986
* ImportSpec ::= id
29872987
* | ‘_’
2988-
* | ‘given’
29892988
* | ‘{’ ImportSelectors) ‘}’
29902989
*/
29912990
def importExpr(mkTree: ImportConstr): () => Tree = {
@@ -3007,15 +3006,16 @@ object Parsers {
30073006
val selector =
30083007
if isWildcard then
30093008
val id = wildcardSelectorId()
3010-
val bound =
3011-
if selToken == USCORE && in.token == COLON then
3009+
if selToken == USCORE then ImportSelector(id)
3010+
else atSpan(startOffset(id)) {
3011+
if in.token == USCORE then
30123012
in.nextToken()
3013-
infixType()
3014-
else if selToken == GIVEN && in.token != RBRACE && in.token != COMMA then
3015-
infixType()
3013+
ImportSelector(id)
3014+
else if in.token != RBRACE && in.token != COMMA then
3015+
ImportSelector(id, bound = infixType())
30163016
else
3017-
EmptyTree
3018-
ImportSelector(id, bound = bound)
3017+
ImportSelector(id) // TODO: drop
3018+
}
30193019
else
30203020
val from = termIdent()
30213021
if !idOK then syntaxError(i"named imports cannot follow wildcard imports")

docs/docs/internals/syntax.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,11 @@ Import ::= ‘import’ ImportExpr {‘,’ ImportExpr}
342342
ImportExpr ::= StableId ‘.’ ImportSpec Import(expr, sels)
343343
ImportSpec ::= id
344344
| ‘_’
345-
| ‘given’
346345
| ‘{’ ImportSelectors) ‘}’
347346
ImportSelectors ::= id [‘=>’ id | ‘=>’ ‘_’] [‘,’ ImportSelectors]
348347
| WildCardSelector {‘,’ WildCardSelector}
349-
WildCardSelector ::= ‘given’ [InfixType]
350-
| ‘_' [‘:’ InfixType]
348+
WildCardSelector ::= ‘given’ (‘_' | InfixType)
349+
| ‘_'
351350
Export ::= ‘export’ [‘given’] ImportExpr {‘,’ ImportExpr}
352351
```
353352

tests/disabled/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import scala.quoted._
2-
import scala.quoted.autolift.given
2+
import scala.quoted.autolift.{given _}
33

44
object Macros {
55

tests/disabled/run/xml-interpolation-3/XmlQuote_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import scala.quoted._
22
import scala.tasty.Tasty
3-
import scala.quoted.autolift.given
3+
import scala.quoted.autolift.{given _}
44

55
import scala.language.implicitConversions
66

tests/neg-custom-args/implicit-conversions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object D {
2121
}
2222

2323
object Test {
24-
import D.given
24+
import D.{given _}
2525

2626
val x1: A = new B
2727
val x2: B = new A // error under -Xfatal-warnings -feature

tests/neg-macros/delegate-match-1/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.quoted.matching._
44
inline def f: Any = ${ fImpl }
55

66
private def fImpl with (qctx: QuoteContext) : Expr[Unit] = {
7-
import qctx.tasty.{_, given}
7+
import qctx.tasty.{_, given _}
88
searchImplicit(('[A]).unseal.tpe) match {
99
case x: ImplicitSearchSuccess =>
1010
'{}

tests/neg-macros/delegate-match-2/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.quoted.matching._
44
inline def f: Any = ${ fImpl }
55

66
private def fImpl with (qctx: QuoteContext) : Expr[Unit] = {
7-
import qctx.tasty.{_, given}
7+
import qctx.tasty.{_, given _}
88
searchImplicit(('[A]).unseal.tpe) match {
99
case x: ImplicitSearchSuccess =>
1010
'{}

tests/neg-macros/delegate-match-3/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.quoted.matching._
44
inline def f: Any = ${ fImpl }
55

66
private def fImpl with (qctx: QuoteContext) : Expr[Unit] = {
7-
import qctx.tasty.{_, given}
7+
import qctx.tasty.{_, given _}
88
searchImplicit(('[A]).unseal.tpe) match {
99
case x: ImplicitSearchSuccess =>
1010
'{}

tests/neg-macros/i6432/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
import scala.quoted._
3-
import scala.quoted.autolift.given
3+
import scala.quoted.autolift.{given _}
44
import scala.quoted.matching._
55

66
object Macro {
77
inline def (sc: => StringContext).foo(args: String*): Unit = ${ impl('sc) }
88

99
def impl(sc: Expr[StringContext]) with (qctx: QuoteContext) : Expr[Unit] = {
10-
import qctx.tasty.{_, given}
10+
import qctx.tasty.{_, given _}
1111
sc match {
1212
case '{ StringContext(${ExprSeq(parts)}: _*) } =>
1313
for (part @ Const(s) <- parts)

0 commit comments

Comments
 (0)