@@ -825,7 +825,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
825825 def tryNamedTupleSelection () =
826826 val namedTupleElems = qual.tpe.widenDealias.namedTupleElementTypes(true )
827827 val nameIdx = namedTupleElems.indexWhere(_._1 == selName)
828- if nameIdx >= 0 && Feature .enabled( Feature .namedTuples) then
828+ if nameIdx >= 0 && sourceVersion.enablesNamedTuples then
829829 typed(
830830 untpd.Apply (
831831 untpd.Select (untpd.TypedSplice (qual), nme.apply),
@@ -3500,19 +3500,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
35003500 /** Checks if `tree` is a named tuple with one element that could be
35013501 * interpreted as an assignment, such as `(x = 1)`. If so, issues a warning.
35023502 */
3503- def checkDeprecatedAssignmentSyntax (tree : untpd.Tuple )(using Context ): Unit =
3504- tree.trees match
3505- case List (NamedArg (name, value)) =>
3503+ def checkDeprecatedAssignmentSyntax (tree : untpd.Tuple | untpd. Parens )(using Context ): Unit =
3504+ val assignmentArgs = tree match {
3505+ case untpd. Tuple ( List (NamedArg (name, value) )) =>
35063506 val tmpCtx = ctx.fresh.setNewTyperState()
35073507 typedAssign(untpd.Assign (untpd.Ident (name), value), WildcardType )(using tmpCtx)
3508- if ! tmpCtx.reporter.hasErrors then
3509- // If there are no errors typing the above, then the named tuple is
3510- // ambiguous and we issue a warning.
3511- report.migrationWarning(DeprecatedAssignmentSyntax (name, value), tree.srcPos)
3512- if MigrationVersion .AmbiguousNamedTupleSyntax .needsPatch then
3513- patch(tree.source, Span (tree.span.start, tree.span.start + 1 ), " {" )
3514- patch(tree.source, Span (tree.span.end - 1 , tree.span.end), " }" )
3515- case _ => ()
3508+ Option .unless(tmpCtx.reporter.hasErrors)(name -> value)
3509+ case untpd.Parens (Assign (ident : untpd.Ident , value)) => Some (ident.name -> value)
3510+ case _ => None
3511+ }
3512+ assignmentArgs.foreach: (name, value) =>
3513+ // If there are no errors typing the above, then the named tuple is
3514+ // ambiguous and we issue a warning.
3515+ report.migrationWarning(DeprecatedAssignmentSyntax (name, value), tree.srcPos)
3516+ if MigrationVersion .AmbiguousNamedTupleSyntax .needsPatch then
3517+ patch(tree.source, Span (tree.span.start, tree.span.start + 1 ), " {" )
3518+ patch(tree.source, Span (tree.span.end - 1 , tree.span.end), " }" )
35163519
35173520 /** Retrieve symbol attached to given tree */
35183521 protected def retrieveSym (tree : untpd.Tree )(using Context ): Symbol = tree.removeAttachment(SymOfTree ) match {
@@ -3621,6 +3624,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
36213624 case tree : untpd.SplicePattern => typedSplicePattern(tree, pt)
36223625 case tree : untpd.MacroTree => report.error(" Unexpected macro" , tree.srcPos); tpd.nullLiteral // ill-formed code may reach here
36233626 case tree : untpd.Hole => typedHole(tree, pt)
3627+ case tree : untpd.Parens =>
3628+ checkDeprecatedAssignmentSyntax(tree)
3629+ typedUnadapted(desugar(tree, pt), pt, locked)
36243630 case _ => typedUnadapted(desugar(tree, pt), pt, locked)
36253631 }
36263632
0 commit comments