Skip to content

Commit e7eb51e

Browse files
committed
[parser] parse indentation region in default argument #SCL-23297 fixed
1 parent 763f40f commit e7eb51e

File tree

2 files changed

+106
-2
lines changed
  • scala/scala-impl
    • src/org/jetbrains/plugins/scala/lang/parser/parsing/params
    • test/org/jetbrains/plugins/scala/lang/parser/scala3

2 files changed

+106
-2
lines changed

scala/scala-impl/src/org/jetbrains/plugins/scala/lang/parser/parsing/params/Param.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.jetbrains.plugins.scala.lang.lexer.{ScalaTokenType, ScalaTokenTypes}
44
import org.jetbrains.plugins.scala.lang.parser.{ErrMsg, ScalaElementType}
55
import org.jetbrains.plugins.scala.lang.parser.parsing.ParsingRule
66
import org.jetbrains.plugins.scala.lang.parser.parsing.builder.ScalaPsiBuilder
7-
import org.jetbrains.plugins.scala.lang.parser.parsing.expressions.{Annotations, Expr}
7+
import org.jetbrains.plugins.scala.lang.parser.parsing.expressions.{Annotations, Expr, ExprInIndentationRegion}
88
import org.jetbrains.plugins.scala.lang.parser.parsing.types.ParamType
99

1010
/**
@@ -49,7 +49,7 @@ object Param extends ParsingRule {
4949
builder.getTokenType match {
5050
case ScalaTokenTypes.tASSIGN =>
5151
builder.advanceLexer() //Ate =
52-
if (!Expr()) builder error ErrMsg("expression.expected")
52+
if (!ExprInIndentationRegion()) builder error ErrMsg("expression.expected")
5353
case _ =>
5454
}
5555
paramMarker.done(ScalaElementType.PARAM)

scala/scala-impl/test/org/jetbrains/plugins/scala/lang/parser/scala3/FunDefTest.scala

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,4 +621,108 @@ class FunDefTest extends SimpleScala3ParserTestBase {
621621
| PsiWhiteSpace('\n')
622622
|""".stripMargin
623623
)
624+
625+
// SCL-23297
626+
def test_indentation_region_in_default_param(): Unit = checkTree(
627+
"""
628+
|def foo0(p: Int =
629+
| var x = 1
630+
| var y = 2
631+
| x + y
632+
|) = {
633+
| println(p)
634+
|}
635+
|""".stripMargin,
636+
"""
637+
|ScalaFile
638+
| PsiWhiteSpace('\n')
639+
| ScFunctionDefinition: foo0
640+
| AnnotationsList
641+
| <empty list>
642+
| Modifiers
643+
| <empty list>
644+
| PsiElement(def)('def')
645+
| PsiWhiteSpace(' ')
646+
| PsiElement(identifier)('foo0')
647+
| Parameters
648+
| ParametersClause
649+
| PsiElement(()('(')
650+
| Parameter: p
651+
| AnnotationsList
652+
| <empty list>
653+
| Modifiers
654+
| <empty list>
655+
| PsiElement(identifier)('p')
656+
| PsiElement(:)(':')
657+
| PsiWhiteSpace(' ')
658+
| ParameterType
659+
| SimpleType: Int
660+
| CodeReferenceElement: Int
661+
| PsiElement(identifier)('Int')
662+
| PsiWhiteSpace(' ')
663+
| PsiElement(=)('=')
664+
| BlockExpression
665+
| PsiWhiteSpace('\n ')
666+
| ScVariableDefinition: x
667+
| AnnotationsList
668+
| <empty list>
669+
| Modifiers
670+
| <empty list>
671+
| PsiElement(var)('var')
672+
| PsiWhiteSpace(' ')
673+
| ListOfPatterns
674+
| ReferencePattern: x
675+
| PsiElement(identifier)('x')
676+
| PsiWhiteSpace(' ')
677+
| PsiElement(=)('=')
678+
| PsiWhiteSpace(' ')
679+
| IntegerLiteral
680+
| PsiElement(integer)('1')
681+
| PsiWhiteSpace('\n ')
682+
| ScVariableDefinition: y
683+
| AnnotationsList
684+
| <empty list>
685+
| Modifiers
686+
| <empty list>
687+
| PsiElement(var)('var')
688+
| PsiWhiteSpace(' ')
689+
| ListOfPatterns
690+
| ReferencePattern: y
691+
| PsiElement(identifier)('y')
692+
| PsiWhiteSpace(' ')
693+
| PsiElement(=)('=')
694+
| PsiWhiteSpace(' ')
695+
| IntegerLiteral
696+
| PsiElement(integer)('2')
697+
| PsiWhiteSpace('\n ')
698+
| InfixExpression
699+
| ReferenceExpression: x
700+
| PsiElement(identifier)('x')
701+
| PsiWhiteSpace(' ')
702+
| ReferenceExpression: +
703+
| PsiElement(identifier)('+')
704+
| PsiWhiteSpace(' ')
705+
| ReferenceExpression: y
706+
| PsiElement(identifier)('y')
707+
| PsiWhiteSpace('\n')
708+
| PsiElement())(')')
709+
| PsiWhiteSpace(' ')
710+
| PsiElement(=)('=')
711+
| PsiWhiteSpace(' ')
712+
| BlockExpression
713+
| PsiElement({)('{')
714+
| PsiWhiteSpace('\n ')
715+
| MethodCall
716+
| ReferenceExpression: println
717+
| PsiElement(identifier)('println')
718+
| ArgumentList
719+
| PsiElement(()('(')
720+
| ReferenceExpression: p
721+
| PsiElement(identifier)('p')
722+
| PsiElement())(')')
723+
| PsiWhiteSpace('\n')
724+
| PsiElement(})('}')
725+
| PsiWhiteSpace('\n')
726+
|""".stripMargin
727+
)
624728
}

0 commit comments

Comments
 (0)