Skip to content

Fix #10074: Disallow given as syntax #10089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3544,7 +3544,7 @@ object Parsers {
then paramClauses(givenOnly = true)
else Nil
newLinesOpt()
if isIdent(nme.as) || !name.isEmpty || !tparams.isEmpty || !vparamss.isEmpty then
if !name.isEmpty || !tparams.isEmpty || !vparamss.isEmpty then
accept(nme.as)
val parents = constrApps(commaOK = true, templateCanFollow = true)
if in.token == EQUALS && parents.length == 1 && parents.head.isType then
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ ObjectDef ::= id [Template]
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
GivenDef ::= [GivenSig] Type ‘=’ Expr
| [GivenSig] ConstrApps [TemplateBody]
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘as’
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘as’ -- one of `id`, `DefParamClause`, `UsingParamClause` must appear
Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’
{UsingParamClause}] ExtMethods
ExtMethods ::= ExtMethod | [nl] ‘{’ ExtMethod {semi ExtMethod ‘}’
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i9014/Macros_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scala.quoted._
trait Bar
inline given as Bar = ${ impl }
inline given Bar = ${ impl }
def impl(using qctx: QuoteContext): Expr[Bar] = report.throwError("Failed to expand!")
2 changes: 1 addition & 1 deletion tests/neg/gadt-approximation-interaction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object GivenConversion {
class Pow(self: Int):
def **(other: Int): Int = math.pow(self, other).toInt

given as Conversion[Int, Pow] = (i: Int) => Pow(i)
given Conversion[Int, Pow] = (i: Int) => Pow(i)

def foo[T](t: T, ev: T SUB Int) =
ev match { case SUB.Refl() =>
Expand Down
3 changes: 3 additions & 0 deletions tests/neg/i10074.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Context
given Context = ??? // ok
given as Context = ??? // error // error // error
2 changes: 1 addition & 1 deletion tests/neg/i8896-a.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ trait Foo[A]

object Example {

given as Foo[Int] {
given Foo[Int] {
}

def foo0[A: Foo]: A => A = identity
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i8896-b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ trait Foo[A]

object Example {

given as Foo[Int] {
given Foo[Int] {
}

def foo0[A: Foo]: A => A = identity
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i9014.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
trait Bar
object Bar:
inline given as Bar = compiletime.error("Failed to expand!")
inline given Bar = compiletime.error("Failed to expand!")
val tests = summon[Bar] // error
2 changes: 1 addition & 1 deletion tests/pos/i9103.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object a:
type Foo[T]
given as Foo[Unit] = ???
given Foo[Unit] = ???

val b = a

Expand Down
2 changes: 1 addition & 1 deletion tests/run/instances-anonymous.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object Test extends App {
val minimum: T
}

given as Ord[Int] {
given Ord[Int] {
extension (x: Int) def compareTo(y: Int) =
if (x < y) -1 else if (x > y) +1 else 0
val minimum = Int.MinValue
Expand Down
6 changes: 3 additions & 3 deletions tests/run/summonAll.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import compiletime.summonAll

@main def Test =
given as Int = 10
given as String = "foo"
given as Double = 1.2
given Int = 10
given String = "foo"
given Double = 1.2
println(summonAll[Int *: String *: Double *: EmptyTuple])