-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Stabilise SIP-47 (Adding Clause Interleaving to method definitions) #20861
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3836,9 +3836,6 @@ object Parsers { | |
|
||
/** DefDef ::= DefSig [‘:’ Type] [‘=’ Expr] | ||
* | this TypelessClauses [DefImplicitClause] `=' ConstrExpr | ||
* DefSig ::= id [DefTypeParamClause] DefTermParamClauses | ||
* | ||
* if clauseInterleaving is enabled: | ||
* DefSig ::= id [DefParamClauses] [DefImplicitClause] | ||
*/ | ||
def defDefOrDcl(start: Offset, mods: Modifiers, numLeadParams: Int = 0): DefDef = atSpan(start, nameStart) { | ||
|
@@ -3878,13 +3875,11 @@ object Parsers { | |
val ident = termIdent() | ||
var name = ident.name.asTermName | ||
val paramss = | ||
if in.featureEnabled(Feature.clauseInterleaving) then | ||
bishabosha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// If you are making interleaving stable manually, please refer to the PR introducing it instead, section "How to make non-experimental" | ||
if Feature.clauseInterleavingEnabled(using in.languageImportContext) then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks out of line with other code that's version dependent, Why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a doc comment further up that needs to be updated.
As far as Parser is concerned, clauseInterleaving is now enabled, so the grammar should reflect this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The issue there is that we also need to check if
hamzaremmal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
typeOrTermParamClauses(ParamOwner.Def, numLeadParams) | ||
else | ||
val tparams = typeParamClauseOpt(ParamOwner.Def) | ||
val vparamss = termParamClauses(ParamOwner.Def, numLeadParams) | ||
|
||
joinParams(tparams, vparamss) | ||
|
||
var tpt = fromWithinReturnType { typedOpt() } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,4 @@ | ||
-- Error: tests/neg/given-loop-prevention.scala:10:36 ------------------------------------------------------------------ | ||
-- [E172] Type Error: tests/neg/given-loop-prevention.scala:10:36 ------------------------------------------------------ | ||
10 | given List[Foo] = List(summon[Foo]) // error | ||
| ^ | ||
| Result of implicit search for Foo will change. | ||
| Current result Baz.given_Foo will be no longer eligible | ||
| because it is not defined before the search position. | ||
| Result with new rules: No Matching Implicit. | ||
| To opt into the new rules, compile with `-source future` or use | ||
| the `scala.language.future` language import. | ||
| | ||
| To fix the problem without the language import, you could try one of the following: | ||
| - use a `given ... with` clause as the enclosing given, | ||
| - rearrange definitions so that Baz.given_Foo comes earlier, | ||
| - use an explicit argument. | ||
| No given instance of type Foo was found for parameter x of method summon in object Predef |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
|
||
trait Monad[T]: | ||
def id: String | ||
class Foo | ||
object Foo { | ||
given Monad[Foo] with { def id = "Foo" } | ||
} | ||
|
||
opaque type Bar = Foo | ||
object Bar { | ||
given Monad[Bar] = summon[Monad[Foo]] // error | ||
given Foo with {} | ||
given List[Foo] = List(summon[Foo]) // ok | ||
} | ||
|
||
object Test extends App { | ||
println(summon[Monad[Foo]].id) | ||
println(summon[Monad[Bar]].id) | ||
object Baz { | ||
@annotation.nowarn | ||
given List[Foo] = List(summon[Foo]) // error | ||
given Foo with {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,9 @@ | ||
-- Error: tests/neg/i7294.scala:7:10 ----------------------------------------------------------------------------------- | ||
7 | case x: T => x.g(10) // error // error | ||
| ^ | ||
| Result of implicit search for scala.reflect.TypeTest[Nothing, T] will change. | ||
| Current result foo.f will be no longer eligible | ||
| because it is not defined before the search position. | ||
| Result with new rules: No Matching Implicit. | ||
| To opt into the new rules, compile with `-source future` or use | ||
| the `scala.language.future` language import. | ||
| | ||
| To fix the problem without the language import, you could try one of the following: | ||
| - use a `given ... with` clause as the enclosing given, | ||
| - rearrange definitions so that foo.f comes earlier, | ||
| - use an explicit argument. | ||
| | ||
| where: T is a type in given instance f with bounds <: foo.Foo | ||
-- [E007] Type Mismatch Error: tests/neg/i7294.scala:7:18 -------------------------------------------------------------- | ||
7 | case x: T => x.g(10) // error // error | ||
| ^^^^^^^ | ||
| Found: Any | ||
| Required: T | ||
| | ||
| where: T is a type in given instance f with bounds <: foo.Foo | ||
-- [E007] Type Mismatch Error: tests/neg/i7294.scala:7:15 -------------------------------------------------------------- | ||
7 | case x: T => x.g(10) // error | ||
| ^ | ||
| Found: (x : Nothing) | ||
| Required: ?{ g: ? } | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than ?{ g: [applied to (10) returning T] } | ||
| | ||
| longer explanation available when compiling with `-explain` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
import scala.language.experimental.clauseInterleaving | ||
|
||
object Ab: | ||
given String = "" | ||
given Double = 0 | ||
|
||
def illegal[A][B](x: A)(using B): B = summon[B] // error: Type parameter lists must be separated by a term or using parameter list | ||
|
||
def ab[A](x: A)[B](using B): B = summon[B] | ||
def test = | ||
ab[Int](0: Int) // error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import scala.language.experimental.clauseInterleaving | ||
|
||
class Params{ | ||
def bar[T](x: T)[T]: String = ??? // error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import scala.language.experimental.clauseInterleaving | ||
|
||
object unmatched: | ||
def f1[T (x: T)] = ??? // error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- [E040] Syntax Error: tests/neg/interleavingExperimental.scala:3:15 -------------------------------------------------- | ||
3 |def ba[A](x: A)[B](using B): B = summon[B] // error: clauseInterleaving was experimental until 3.6 | ||
| ^ | ||
| '=' expected, but '[' found |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//> using options --source 3.5 | ||
|
||
def ba[A](x: A)[B](using B): B = summon[B] // error: clauseInterleaving was experimental until 3.6 |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldn't be mixing source version with language import checks, they should be kept separate,
e.g. in the parser do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure to see why we should do that ?
edit:
fewerBraces
was stabilised in3.3
and we do similarly:scala3/compiler/src/dotty/tools/dotc/config/Feature.scala
Line 165 in 75a15c2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I guess its fine then, curious that in parser they just have
Feature.fewerBracesEnabled
without explicit usingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I was currious too. I guess it might be a no-op as it is, therefore a bug ?