Skip to content

Commit 398c8ce

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 f9e20cf commit 398c8ce

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)

tests/neg-macros/i6432b/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)

tests/neg-macros/i6976/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package playground
22

33
import scala.quoted._, scala.quoted.matching._
4-
import scala.quoted.given
4+
import scala.quoted.{given _}
55
import scala.tasty._
66

77
object macros {
88
inline def mcr(x: => Any) = ${mcrImpl('x)}
99

1010
def mcrImpl(body: Expr[Any]) with (ctx: QuoteContext) : Expr[Any] = {
11-
import ctx.tasty.{_, given}
11+
import ctx.tasty.{_, given _}
1212
body.unseal match { case Block(_, _) => '{2} }
1313
}
1414
}

tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

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

55
object E {
66

tests/neg-macros/inline-tuples-1/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

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

55
object Macros {
66
def tup1(tup: Tuple1[Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum

tests/neg-macros/quote-interpolator-core-old.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
// This test checks the correct interpretation of the inlined value class
55

tests/neg-macros/quote-macro-splice.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 Test {
55

tests/neg-macros/splice-in-top-level-splice-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 Foo {
55
inline def foo(): Int = ${bar(${x})} // error

tests/neg-macros/tasty-macro-assert-1/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Asserts {
1313
${impl('cond)}
1414

1515
def impl(cond: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = {
16-
import qctx.tasty.{_, given}
16+
import qctx.tasty.{_, given _}
1717

1818
val tree = cond.unseal
1919

tests/neg-macros/tasty-macro-assert-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Asserts {
1313
${ impl('cond) }
1414

1515
def impl(cond: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = {
16-
import qctx.tasty.{_, given}
16+
import qctx.tasty.{_, given _}
1717

1818
val tree = cond.unseal
1919

tests/neg-macros/tasty-macro-error/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Macros {
55
inline def fun(x: Any): Unit = ${ impl('x) }
66

77
def impl(x: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = {
8-
import qctx.tasty.{_, given}
8+
import qctx.tasty.{_, given _}
99
error("here is the the argument is " + x.unseal.underlyingArgument.show, x.unseal.underlyingArgument.pos)
1010
'{}
1111
}

tests/neg-macros/tasty-macro-positions/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Macros {
55
inline def fun(x: Any): Unit = ${ impl('x) }
66

77
def impl(x: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = {
8-
import qctx.tasty.{_, given}
8+
import qctx.tasty.{_, given _}
99
val pos = x.unseal.underlyingArgument.pos
1010
error("here is the the argument is " + x.unseal.underlyingArgument.show, pos)
1111
error("here (+5) is the the argument is " + x.unseal.underlyingArgument.show, pos.sourceFile, pos.start + 5, pos.end + 5)

tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Macro {
1010
object FIntepolator {
1111

1212
def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) with (qctx: QuoteContext) : Expr[String] = {
13-
import qctx.tasty.{_, given}
13+
import qctx.tasty.{_, given _}
1414
error("there are no parts", strCtxExpr.unseal.underlyingArgument.pos)
1515
'{ ($strCtxExpr).s($argsExpr: _*) }
1616
}

tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Macro {
99

1010
object FIntepolator {
1111
def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) with (qctx: QuoteContext) : Expr[String] = {
12-
import qctx.tasty.{_, given}
12+
import qctx.tasty.{_, given _}
1313
error("there are no args", argsExpr.unseal.underlyingArgument.pos)
1414
'{ ($strCtxExpr).s($argsExpr: _*) }
1515
}

tests/neg-staging/i5941/macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Lens {
1313

1414
def impl[S: Type, T: Type](getter: Expr[S => T]) with (qctx: QuoteContext) : Expr[Lens[S, T]] = {
1515
implicit val toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(this.getClass.getClassLoader)
16-
import qctx.tasty.{_, given}
16+
import qctx.tasty.{_, given _}
1717
import util._
1818
// obj.copy(field = value)
1919
def setterBody(obj: Expr[S], value: Expr[T], field: String): Expr[S] =

tests/neg-staging/quote-run-in-macro-1/quoted_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.quoted.staging._
3-
import scala.quoted.autolift.given
3+
import scala.quoted.autolift.{given _}
44

55
object Macros {
66

tests/neg/i6762.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.quoted.{_, given}
1+
import scala.quoted.{_, given _}
22

33
type G[X]
44
case class Foo[T](x: T)

tests/neg/i6997b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package playground
22

3-
import scala.quoted.{_, given}, scala.quoted.matching._
3+
import scala.quoted.{_, given _}, scala.quoted.matching._
44

55
inline def mcr(x: => Any): Any = ${mcrImpl('x)}
66

tests/neg/i7618.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package macros
22

3-
import scala.quoted.{given, _}
3+
import scala.quoted.{given _, _}
44

55
enum Exp {
66
case Num(n: Int)

tests/neg/i7618b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package macros
22

3-
import scala.quoted.{given, _}
3+
import scala.quoted.{given _, _}
44

55
enum Exp {
66
case Num(n: Int)

tests/neg/i7919.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.quoted._
22

33
object Test {
44
def staged[T] with (qctx: QuoteContext) = {
5-
import qctx.tasty.{_, given}
5+
import qctx.tasty.{_, given _}
66
given typeT as quoted.Type[T] // error
77
val tTypeTree = typeT.unseal
88
val tt = typeOf[T]

tests/neg/import-implied.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ object C {
1616
foo.with(tc) // ok
1717
}
1818
object D {
19-
import A.{foo, given}
19+
import A.{foo, given _}
2020
foo // ok
2121
foo.with(tc) // ok
2222
}
2323
object E {
24-
import A.{_, given}
24+
import A.{_, given _}
2525
foo // ok
2626
foo.with(tc) // ok
2727
}

tests/neg/toexproftuple.scala

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

44
inline def mcr: Any = ${mcrImpl}
55
def mcrImpl with (ctx: QuoteContext) : Expr[Any] = {

tests/pending/run/tasty-comments/quoted_1.scala

Lines changed: 2 additions & 2 deletions
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

55
object Macros {
@@ -8,7 +8,7 @@ object Macros {
88
${ impl('t) }
99

1010
def impl[T](x: Expr[T]) with (qctx: QuoteContext) : Expr[Unit] = {
11-
import qctx.tasty.{_, given}
11+
import qctx.tasty.{_, given _}
1212

1313
val tree = x.unseal
1414
tree.symbol.comment.map(_.raw) match {

tests/pos-macros/i6171/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object scalatest {
55
inline def assert(x: => Any): Unit = ${ assertImpl('x) }
66

77
def assertImpl(x: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = {
8-
import qctx.tasty.{_, given}
8+
import qctx.tasty.{_, given _}
99
x.unseal.underlyingArgument
1010
'{ () }
1111
}

tests/pos-macros/i6535/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object scalatest {
55
inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition) }
66

77
def assertImpl(cond: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = {
8-
import qctx.tasty.{_, given}
8+
import qctx.tasty.{_, given _}
99
import util._
1010

1111
cond.unseal.underlyingArgument match {

tests/pos-macros/i6803b/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package blah
22

33
import scala.language.implicitConversions
44
import scala.quoted._
5-
import scala.quoted.autolift.given
5+
import scala.quoted.autolift.{given _}
66

77
object AsObject {
88
final class LineNo(val lineNo: Int)
99
object LineNo {
1010
def unsafe(i: Int): LineNo = new LineNo(i)
1111
inline given x : LineNo = ${impl}
1212
private def impl with (qctx: QuoteContext) : Expr[LineNo] = {
13-
import qctx.tasty.{_, given}
13+
import qctx.tasty.{_, given _}
1414
'{unsafe(${rootPosition.startLine})}
1515
}
1616
}

tests/pos-macros/i7011/Macros_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import scala.quoted._, scala.quoted.matching._
2-
import scala.quoted.given
2+
import scala.quoted.{given _}
33

44
inline def mcr(body: => Any): Unit = ${mcrImpl('body)}
55

66
def mcrImpl[T](body: Expr[Any]) with (ctx: QuoteContext) : Expr[Any] = {
7-
import ctx.tasty.{_, given}
7+
import ctx.tasty.{_, given _}
88

99
val bTree = body.unseal
1010
val under = bTree.underlyingArgument

tests/pos-macros/i7853/SummonJsonEncoderTest_2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.deriving._
22
import scala.quoted._
33
import scala.quoted.matching._
44
import scala.compiletime.{erasedValue, summonFrom}
5-
import JsonEncoder.{given, _}
5+
import JsonEncoder.{given _, _}
66

77
object SummonJsonEncoderTest {
88

tests/pos-macros/quote-nested-object/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

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

55
object Macro {
66

0 commit comments

Comments
 (0)