Closed
Description
Description
When using string interpolation with a trailing comma, the parser appears to skip the subsequent expression entirely. As a result, the expression is not properly parsed and is missing from the AST.
Reproduction
compile the following code.
"\(1,)" // following expression are not parsed
print("a") // won't be executed
lethoge:;:;{}:;$$@@@/po
(・w・)っ@MainActor!!!!
今日は星が綺麗
output (not output, only the warning appears)
swift Source.swift
Source.swift:1:1: warning: string literal is unused
1 | "\(1,)" // following expression are not parsed
| `- warning: string literal is unused
2 | print("a") // won't be executed
3 | lethoge:;:;{}:;$$@@@/po
Expected behavior
compiler should emit error/correctly parse the subsequent expressions into AST.
Environment
swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0
Additional information
dump AST
swiftc -dump-ast Source.swift
(source_file "Source.swift"
(top_level_code_decl range=[Source.swift:1:1 - line:1:1]
(brace_stmt implicit range=[Source.swift:1:1 - line:1:1]
(interpolated_string_literal_expr type="String" location=Source.swift:1:1 range=[Source.swift:1:1 - line:1:1] literal_capacity=0 interpolation_count=1 builder_init="Swift.(file).DefaultStringInterpolation.init(literalCapacity:interpolationCount:)" result_init="Swift.(file).String extension.init(stringInterpolation:)"
(tap_expr implicit type="String.StringInterpolation" location=Source.swift:1:1 range=[Source.swift:1:1 - line:1:7] var="Source.(file).top-level code.$interpolation"
(opaque_value_expr implicit type="String.StringInterpolation" location=Source.swift:1:1 range=[Source.swift:1:1 - line:1:1] "0x1229da660")
(brace_stmt implicit range=[Source.swift:1:2 - line:1:7]
(var_decl implicit "$interpolation" interface_type="String.StringInterpolation" access=fileprivate readImpl=stored writeImpl=stored readWriteImpl=stored)
(call_expr implicit type="()" location=Source.swift:1:2 range=[Source.swift:1:2 - line:1:1] nothrow isolation_crossing="none"
(dot_syntax_call_expr implicit type="(String) -> ()" location=Source.swift:1:2 range=[Source.swift:1:2 - line:1:2] nothrow isolation_crossing="none"
(declref_expr implicit type="(inout DefaultStringInterpolation) -> (String) -> ()" decl="Swift.(file).DefaultStringInterpolation.appendLiteral" function_ref=single_apply)
(argument_list implicit
(argument inout
(inout_expr implicit type="inout DefaultStringInterpolation" location=Source.swift:1:2 range=[Source.swift:1:2 - line:1:2]
(declref_expr implicit type="@lvalue String.StringInterpolation" location=Source.swift:1:2 range=[Source.swift:1:2 - line:1:2] decl="Source.(file).top-level code.$interpolation" function_ref=unapplied)))))
(argument_list implicit
(argument
(string_literal_expr type="String" location=Source.swift:1:1 range=[Source.swift:1:1 - line:1:1] encoding=utf8 value="" builtin_initializer="Swift.(file).String extension.init(_builtinStringLiteral:utf8CodeUnitCount:isASCII:)" initializer="**NULL**"))))
(call_expr type="()" location=Source.swift:1:3 range=[Source.swift:1:3 - line:1:6] nothrow isolation_crossing="none"
(dot_syntax_call_expr implicit type="(Int) -> ()" location=Source.swift:1:3 range=[Source.swift:1:3 - line:1:3] nothrow isolation_crossing="none"
(declref_expr implicit type="(inout DefaultStringInterpolation) -> (Int) -> ()" location=Source.swift:1:3 range=[Source.swift:1:3 - line:1:3] decl="Swift.(file).DefaultStringInterpolation.appendInterpolation [with (substitution_map generic_signature=<T where T : CustomStringConvertible> T -> Int)]" function_ref=single_apply)
(argument_list implicit
(argument inout
(inout_expr implicit type="inout DefaultStringInterpolation" location=Source.swift:1:3 range=[Source.swift:1:3 - line:1:3]
(declref_expr implicit type="@lvalue String.StringInterpolation" location=Source.swift:1:3 range=[Source.swift:1:3 - line:1:3] decl="Source.(file).top-level code.$interpolation" function_ref=unapplied)))))
(argument_list
(argument
(integer_literal_expr type="Int" location=Source.swift:1:4 range=[Source.swift:1:4 - line:1:4] value="1" builtin_initializer="Swift.(file).Int.init(_builtinIntegerLiteral:)" initializer="**NULL**"))))
(call_expr implicit type="()" location=Source.swift:1:7 range=[Source.swift:1:7 - line:1:7] nothrow isolation_crossing="none"
(dot_syntax_call_expr implicit type="(String) -> ()" location=Source.swift:1:7 range=[Source.swift:1:7 - line:1:7] nothrow isolation_crossing="none"
(declref_expr implicit type="(inout DefaultStringInterpolation) -> (String) -> ()" decl="Swift.(file).DefaultStringInterpolation.appendLiteral" function_ref=single_apply)
(argument_list implicit
(argument inout
(inout_expr implicit type="inout DefaultStringInterpolation" location=Source.swift:1:7 range=[Source.swift:1:7 - line:1:7]
(declref_expr implicit type="@lvalue String.StringInterpolation" location=Source.swift:1:7 range=[Source.swift:1:7 - line:1:7] decl="Source.(file).top-level code.$interpolation" function_ref=unapplied)))))
(argument_list implicit
(argument
(string_literal_expr type="String" location=Source.swift:1:7 range=[Source.swift:1:7 - line:1:7] encoding=utf8 value="" builtin_initializer="Swift.(file).String extension.init(_builtinStringLiteral:utf8CodeUnitCount:isASCII:)" initializer="**NULL**"))))))))))
Source.swift:1:1: warning: string literal is unused
1 | "\(1,)" // following expression are not parsed
| `- warning: string literal is unused
2 | print("a") // won't be executed
3 | lethoge:;:;{}:;$$@@@/po