From dc4bfd1e0916788c14e6393197b7eb821d8af243 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 26 Oct 2020 17:58:22 +0100 Subject: [PATCH 1/3] Fix #10074: Disallow `given as` syntax --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- docs/docs/internals/syntax.md | 2 +- tests/neg/i10074.scala | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i10074.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index eea9977aad21..a9f097eff3ab 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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 diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 9819bd4ee770..efb0febc01aa 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -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 ‘}’ diff --git a/tests/neg/i10074.scala b/tests/neg/i10074.scala new file mode 100644 index 000000000000..3afcdea08f1a --- /dev/null +++ b/tests/neg/i10074.scala @@ -0,0 +1,3 @@ +class Context +given as as Context = ??? // ok +given as Context = ??? // error // error // error From 56ac15d88b5fb17e6fb2df3bd08696c24bb7697e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 26 Oct 2020 19:58:39 +0100 Subject: [PATCH 2/3] Fix tests --- tests/neg-macros/i9014/Macros_1.scala | 2 +- tests/neg/gadt-approximation-interaction.scala | 2 +- tests/neg/i10074.scala | 2 +- tests/neg/i8896-a.scala | 2 +- tests/neg/i8896-b.scala | 2 +- tests/neg/i9014.scala | 2 +- tests/pos/i9103.scala | 2 +- tests/run/instances-anonymous.scala | 2 +- tests/run/summonAll.scala | 6 +++--- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/neg-macros/i9014/Macros_1.scala b/tests/neg-macros/i9014/Macros_1.scala index 2f1d4250cdca..72d45c144b22 100644 --- a/tests/neg-macros/i9014/Macros_1.scala +++ b/tests/neg-macros/i9014/Macros_1.scala @@ -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!") diff --git a/tests/neg/gadt-approximation-interaction.scala b/tests/neg/gadt-approximation-interaction.scala index 4ece60c2533a..bd8e691b6da9 100644 --- a/tests/neg/gadt-approximation-interaction.scala +++ b/tests/neg/gadt-approximation-interaction.scala @@ -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() => diff --git a/tests/neg/i10074.scala b/tests/neg/i10074.scala index 3afcdea08f1a..54a6701b44cb 100644 --- a/tests/neg/i10074.scala +++ b/tests/neg/i10074.scala @@ -1,3 +1,3 @@ class Context -given as as Context = ??? // ok +given Context = ??? // ok given as Context = ??? // error // error // error diff --git a/tests/neg/i8896-a.scala b/tests/neg/i8896-a.scala index 80cf372a7205..595a46b7a0f2 100644 --- a/tests/neg/i8896-a.scala +++ b/tests/neg/i8896-a.scala @@ -4,7 +4,7 @@ trait Foo[A] object Example { - given as Foo[Int] { + given Foo[Int] { } def foo0[A: Foo]: A => A = identity diff --git a/tests/neg/i8896-b.scala b/tests/neg/i8896-b.scala index 685566930af9..58430fde191a 100644 --- a/tests/neg/i8896-b.scala +++ b/tests/neg/i8896-b.scala @@ -4,7 +4,7 @@ trait Foo[A] object Example { - given as Foo[Int] { + given Foo[Int] { } def foo0[A: Foo]: A => A = identity diff --git a/tests/neg/i9014.scala b/tests/neg/i9014.scala index 827e111d6116..2a82d54be9d9 100644 --- a/tests/neg/i9014.scala +++ b/tests/neg/i9014.scala @@ -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 diff --git a/tests/pos/i9103.scala b/tests/pos/i9103.scala index 03772227537d..71f5c99d8007 100644 --- a/tests/pos/i9103.scala +++ b/tests/pos/i9103.scala @@ -1,6 +1,6 @@ object a: type Foo[T] - given as Foo[Unit] = ??? + given Foo[Unit] = ??? val b = a diff --git a/tests/run/instances-anonymous.scala b/tests/run/instances-anonymous.scala index d2df14152cd4..4a189f9811ce 100644 --- a/tests/run/instances-anonymous.scala +++ b/tests/run/instances-anonymous.scala @@ -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 diff --git a/tests/run/summonAll.scala b/tests/run/summonAll.scala index b4638d7e6ee6..38b19c66d8d2 100644 --- a/tests/run/summonAll.scala +++ b/tests/run/summonAll.scala @@ -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]) From 3da8fa19a60afa161a40d787509ca6b35ecf1288 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 26 Oct 2020 21:34:11 +0100 Subject: [PATCH 3/3] Fix community build scodec --- community-build/community-projects/scodec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community-build/community-projects/scodec b/community-build/community-projects/scodec index ca8a034b3acc..17858b32a28a 160000 --- a/community-build/community-projects/scodec +++ b/community-build/community-projects/scodec @@ -1 +1 @@ -Subproject commit ca8a034b3acc14ad0db93fad87c191a22de0ffbf +Subproject commit 17858b32a28a7a0a226e30e2ce688d84ec9fed00