@@ -920,16 +920,6 @@ object Parsers {
920
920
val next = in.lookahead.token
921
921
next == LBRACKET || next == LPAREN
922
922
923
- private def withEndMigrationWarning (): Boolean =
924
- migrateTo3
925
- && {
926
- warning(
927
- em """ In Scala 3, `with` at the end of a line will start definitions,
928
- |so it cannot be used in front of a parent constructor anymore.
929
- |Place the `with` at the beginning of the next line instead. """ )
930
- true
931
- }
932
-
933
923
/** Does a template start after `with`? This is the case if either
934
924
* - the next token is `{`
935
925
* - the `with` is at the end of a line
@@ -941,7 +931,17 @@ object Parsers {
941
931
val lookahead = in.LookaheadScanner ()
942
932
lookahead.nextToken()
943
933
lookahead.token == LBRACE
944
- || lookahead.isAfterLineEnd && ! withEndMigrationWarning()
934
+ || lookahead.isAfterLineEnd
935
+ && {
936
+ if migrateTo3 then
937
+ warning(
938
+ em """ In Scala 3, `with` at the end of a line will start definitions,
939
+ |so it cannot be used in front of a parent constructor anymore.
940
+ |Place the `with` at the beginning of the next line instead. """ )
941
+ false
942
+ else
943
+ true
944
+ }
945
945
|| (lookahead.isIdent || lookahead.token == THIS )
946
946
&& {
947
947
lookahead.nextToken()
@@ -953,20 +953,6 @@ object Parsers {
953
953
|| lookahead.token == ARROW
954
954
}
955
955
956
- /** Does a refinement start after `with`? This is the case if either
957
- * - the next token is `{`
958
- * - the `with` is at the end of a line and is followed by a token that starts a declaration
959
- */
960
- def followingIsRefinementStart () =
961
- val lookahead = in.LookaheadScanner ()
962
- lookahead.nextToken()
963
- lookahead.token == LBRACE
964
- || lookahead.isAfterLineEnd
965
- && {
966
- if lookahead.token == INDENT then lookahead.nextToken()
967
- dclIntroTokens.contains(lookahead.token)
968
- }
969
-
970
956
/* --------- OPERAND/OPERATOR STACK --------------------------------------- */
971
957
972
958
var opStack : List [OpInfo ] = Nil
@@ -1598,8 +1584,11 @@ object Parsers {
1598
1584
def withType (): Tree = withTypeRest(annotType())
1599
1585
1600
1586
def withTypeRest (t : Tree ): Tree =
1601
- if in.token == WITH && ! followingIsRefinementStart() then
1602
- in.nextTokenNoIndent()
1587
+ def isRefinementStart =
1588
+ val la = in.lookahead
1589
+ la.isAfterLineEnd || la.token == LBRACE
1590
+ if in.token == WITH && ! isRefinementStart then
1591
+ in.nextToken()
1603
1592
if sourceVersion.isAtLeast(`3.1`) then
1604
1593
deprecationWarning(DeprecatedWithOperator ())
1605
1594
atSpan(startOffset(t)) { makeAndType(t, withType()) }
@@ -3869,7 +3858,8 @@ object Parsers {
3869
3858
if (name != nme.ERROR )
3870
3859
self = makeSelfDef(name, tpt).withSpan(first.span)
3871
3860
}
3872
- in.nextTokenNoIndent()
3861
+ in.token = SELFARROW // suppresses INDENT insertion after `=>`
3862
+ in.nextToken()
3873
3863
}
3874
3864
else {
3875
3865
stats += first
0 commit comments