Skip to content
Open
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
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4005,13 +4005,17 @@ object Parsers {
def givenDef(start: Offset, mods: Modifiers, givenMod: Mod) = atSpan(start, nameStart) {
var mods1 = addMod(mods, givenMod)
val nameStart = in.offset
val name = if isIdent && followingIsGivenSig() then ident() else EmptyTermName

val givenSigPart =
if isIdent && followingIsGivenSig() then Some(ident())
else if followingIsGivenSig() then Some(EmptyTermName)
else None
val name = givenSigPart.getOrElse(EmptyTermName)
val gdef =
val tparams = typeParamClauseOpt(ParamOwner.Given)
newLineOpt()
val vparamss =
if in.token == LPAREN && in.lookahead.isIdent(nme.using)
if in.token == LPAREN && givenSigPart.nonEmpty
then termParamClauses(ParamOwner.Given)
else Nil
newLinesOpt()
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i19402.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/i19402.scala:9:12 ----------------------------------------------------------------------------------
9 | given bar(foo: Foo): Bar = Bar(foo) // error
| ^^^
| `using` expected
11 changes: 11 additions & 0 deletions tests/neg/i19402.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
object Example {

class Bar(foo: Foo)

class Foo

given Foo = Foo()

given bar(foo: Foo): Bar = Bar(foo) // error

}
16 changes: 16 additions & 0 deletions tests/neg/i8150.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Error: tests/neg/i8150.scala:3:16 -----------------------------------------------------------------------------------
3 |type T = {given A with A} // error
| ^^^^^^^^^^^^^^
| refinement cannot be `given`
-- [E040] Syntax Error: tests/neg/i8150.scala:4:23 ---------------------------------------------------------------------
4 |type T = {given(using a: A) as B} // error // error
| ^
| an identifier expected, but ':' found
-- [E040] Syntax Error: tests/neg/i8150.scala:4:28 ---------------------------------------------------------------------
4 |type T = {given(using a: A) as B} // error // error
| ^^
| 'with' expected, but identifier found
-- [E040] Syntax Error: tests/neg/i8150.scala:5:8 ----------------------------------------------------------------------
5 |// error
| ^
| '}' expected, but eof found
4 changes: 3 additions & 1 deletion tests/neg/i8150.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
trait A
trait B
type T = {given(using a: A) as B} // error: refinement cannot be `given`
type T = {given A with A} // error
type T = {given(using a: A) as B} // error // error
// error