Skip to content

Commit a5f8e2b

Browse files
authored
Merge pull request #10089 from dotty-staging/fix-#10074
Fix #10074: Disallow `given as` syntax
2 parents 85964c0 + 3da8fa1 commit a5f8e2b

File tree

12 files changed

+16
-13
lines changed

12 files changed

+16
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3543,7 +3543,7 @@ object Parsers {
35433543
then paramClauses(givenOnly = true)
35443544
else Nil
35453545
newLinesOpt()
3546-
if isIdent(nme.as) || !name.isEmpty || !tparams.isEmpty || !vparamss.isEmpty then
3546+
if !name.isEmpty || !tparams.isEmpty || !vparamss.isEmpty then
35473547
accept(nme.as)
35483548
val parents = constrApps(commaOK = true, templateCanFollow = true)
35493549
if in.token == EQUALS && parents.length == 1 && parents.head.isType then

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ ObjectDef ::= id [Template]
401401
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
402402
GivenDef ::= [GivenSig] Type ‘=’ Expr
403403
| [GivenSig] ConstrApps [TemplateBody]
404-
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘as’
404+
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘as’ -- one of `id`, `DefParamClause`, `UsingParamClause` must appear
405405
Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’
406406
{UsingParamClause}] ExtMethods
407407
ExtMethods ::= ExtMethod | [nl] ‘{’ ExtMethod {semi ExtMethod ‘}’

tests/neg-macros/i9014/Macros_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import scala.quoted._
22
trait Bar
3-
inline given as Bar = ${ impl }
3+
inline given Bar = ${ impl }
44
def impl(using qctx: QuoteContext): Expr[Bar] = report.throwError("Failed to expand!")

tests/neg/gadt-approximation-interaction.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ object GivenConversion {
6363
class Pow(self: Int):
6464
def **(other: Int): Int = math.pow(self, other).toInt
6565

66-
given as Conversion[Int, Pow] = (i: Int) => Pow(i)
66+
given Conversion[Int, Pow] = (i: Int) => Pow(i)
6767

6868
def foo[T](t: T, ev: T SUB Int) =
6969
ev match { case SUB.Refl() =>

tests/neg/i10074.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Context
2+
given Context = ??? // ok
3+
given as Context = ??? // error // error // error

tests/neg/i8896-a.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ trait Foo[A]
44

55
object Example {
66

7-
given as Foo[Int] {
7+
given Foo[Int] {
88
}
99

1010
def foo0[A: Foo]: A => A = identity

tests/neg/i8896-b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ trait Foo[A]
44

55
object Example {
66

7-
given as Foo[Int] {
7+
given Foo[Int] {
88
}
99

1010
def foo0[A: Foo]: A => A = identity

tests/neg/i9014.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
trait Bar
22
object Bar:
3-
inline given as Bar = compiletime.error("Failed to expand!")
3+
inline given Bar = compiletime.error("Failed to expand!")
44
val tests = summon[Bar] // error

tests/pos/i9103.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object a:
22
type Foo[T]
3-
given as Foo[Unit] = ???
3+
given Foo[Unit] = ???
44

55
val b = a
66

tests/run/instances-anonymous.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ object Test extends App {
6363
val minimum: T
6464
}
6565

66-
given as Ord[Int] {
66+
given Ord[Int] {
6767
extension (x: Int) def compareTo(y: Int) =
6868
if (x < y) -1 else if (x > y) +1 else 0
6969
val minimum = Int.MinValue

tests/run/summonAll.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import compiletime.summonAll
22

33
@main def Test =
4-
given as Int = 10
5-
given as String = "foo"
6-
given as Double = 1.2
4+
given Int = 10
5+
given String = "foo"
6+
given Double = 1.2
77
println(summonAll[Int *: String *: Double *: EmptyTuple])

0 commit comments

Comments
 (0)