Skip to content

Commit 0fc2752

Browse files
committed
Allow literals as given types
Fixes #11102
1 parent 5672999 commit 0fc2752

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3534,7 +3534,9 @@ object Parsers {
35343534
newLinesOpt()
35353535
val noParams = tparams.isEmpty && vparamss.isEmpty
35363536
if !(name.isEmpty && noParams) then accept(COLON)
3537-
val parents = constrApp() :: withConstrApps()
3537+
val parents =
3538+
if isSimpleLiteral then toplevelTyp() :: Nil
3539+
else constrApp() :: withConstrApps()
35383540
val parentsIsType = parents.length == 1 && parents.head.isType
35393541
if in.token == EQUALS && parentsIsType then
35403542
accept(EQUALS)

tests/pos/i11102.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
given s: "literal" = "literal" // compile error
2+
given "foo" = "foo"
3+
given x: 1 = 1

0 commit comments

Comments
 (0)