Skip to content

Commit b57b985

Browse files
committed
Revert "Allow with in refinements"
This reverts commit 280f094.
1 parent 65aead7 commit b57b985

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,32 +1566,33 @@ object Parsers {
15661566
def infixTypeRest(t: Tree): Tree =
15671567
infixOps(t, canStartTypeTokens, refinedType, isType = true, isOperator = !isPostfixStar)
15681568

1569-
/** RefinedType ::= WithType {[nl | ‘with’] Refinement}
1569+
/** RefinedType ::= WithType {[nl] Refinement}
15701570
*/
15711571
val refinedType: () => Tree = () => refinedTypeRest(withType())
15721572

1573-
def refinedTypeRest(t: Tree): Tree =
1573+
def refinedTypeRest(t: Tree): Tree = {
15741574
argumentStart()
1575-
if isTemplateBodyStart then
1576-
if in.token == WITH then in.nextToken()
1575+
if (in.isNestedStart)
15771576
refinedTypeRest(atSpan(startOffset(t)) {
15781577
RefinedTypeTree(rejectWildcardType(t), refinement(indentOK = true))
15791578
})
15801579
else t
1580+
}
15811581

15821582
/** WithType ::= AnnotType {`with' AnnotType} (deprecated)
15831583
*/
15841584
def withType(): Tree = withTypeRest(annotType())
15851585

15861586
def withTypeRest(t: Tree): Tree =
1587-
def isRefinementStart =
1588-
val la = in.lookahead
1589-
la.isAfterLineEnd || la.token == LBRACE
1590-
if in.token == WITH && !isRefinementStart then
1587+
if in.token == WITH then
1588+
val withOffset = in.offset
15911589
in.nextToken()
1592-
if sourceVersion.isAtLeast(`3.1`) then
1593-
deprecationWarning(DeprecatedWithOperator())
1594-
atSpan(startOffset(t)) { makeAndType(t, withType()) }
1590+
if in.token == LBRACE || in.token == INDENT then
1591+
t
1592+
else
1593+
if sourceVersion.isAtLeast(`3.1`) then
1594+
deprecationWarning(DeprecatedWithOperator(), withOffset)
1595+
atSpan(startOffset(t)) { makeAndType(t, withType()) }
15951596
else t
15961597

15971598
/** AnnotType ::= SimpleType {Annotation}

tests/pos/abstract-givens.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/pos/refinements.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ trait UU {
1010
type UX
1111
val u: UX
1212
val x: this.type & { type UX = Int }
13-
val x1: this.type { type UX = Int }
14-
val x2: this.type with { type UX = Int }
15-
val x3: this.type with
16-
type UX = Int
1713
val y: Int = x.u
1814
val z: x.UX = y
1915
}

0 commit comments

Comments
 (0)