@@ -825,7 +825,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
825
825
def tryNamedTupleSelection () =
826
826
val namedTupleElems = qual.tpe.widenDealias.namedTupleElementTypes(true )
827
827
val nameIdx = namedTupleElems.indexWhere(_._1 == selName)
828
- if nameIdx >= 0 && Feature .enabled( Feature .namedTuples) then
828
+ if nameIdx >= 0 && sourceVersion.enablesNamedTuples then
829
829
typed(
830
830
untpd.Apply (
831
831
untpd.Select (untpd.TypedSplice (qual), nme.apply),
@@ -3500,19 +3500,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3500
3500
/** Checks if `tree` is a named tuple with one element that could be
3501
3501
* interpreted as an assignment, such as `(x = 1)`. If so, issues a warning.
3502
3502
*/
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) )) =>
3506
3506
val tmpCtx = ctx.fresh.setNewTyperState()
3507
3507
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), " }" )
3516
3519
3517
3520
/** Retrieve symbol attached to given tree */
3518
3521
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
3621
3624
case tree : untpd.SplicePattern => typedSplicePattern(tree, pt)
3622
3625
case tree : untpd.MacroTree => report.error(" Unexpected macro" , tree.srcPos); tpd.nullLiteral // ill-formed code may reach here
3623
3626
case tree : untpd.Hole => typedHole(tree, pt)
3627
+ case tree : untpd.Parens =>
3628
+ checkDeprecatedAssignmentSyntax(tree)
3629
+ typedUnadapted(desugar(tree, pt), pt, locked)
3624
3630
case _ => typedUnadapted(desugar(tree, pt), pt, locked)
3625
3631
}
3626
3632
0 commit comments