Skip to content

Commit f685688

Browse files
committed
Elements. Fix for interpolation identifier reading from summary.
Accidentally found it while running golden master tests for fine-grained dependencies. Change-Id: Iad63c59128d0d4534162879d36ab752c8a2b2d00 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441828 Reviewed-by: Paul Berry <[email protected]>
1 parent 7415048 commit f685688

File tree

3 files changed

+153
-1
lines changed

3 files changed

+153
-1
lines changed

pkg/analyzer/lib/src/summary2/ast_binary_reader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ class AstBinaryReader {
830830
return InterpolationExpressionImpl(
831831
leftBracket:
832832
isIdentifier
833-
? Tokens.openCurlyBracket()
833+
? Tokens.stringInterpolationIdentifier()
834834
: Tokens.stringInterpolationExpression(),
835835
expression: expression,
836836
rightBracket: isIdentifier ? null : Tokens.closeCurlyBracket(),

pkg/analyzer/lib/src/summary2/ast_binary_tokens.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ class Tokens {
184184
static Token stringInterpolationExpression() =>
185185
TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION);
186186

187+
static Token stringInterpolationIdentifier() =>
188+
TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_IDENTIFIER);
189+
187190
static Token super_() => TokenFactory.tokenFromKeyword(Keyword.SUPER);
188191

189192
static Token switch_() => TokenFactory.tokenFromKeyword(Keyword.SWITCH);

pkg/analyzer/test/src/summary/elements/class_test.dart

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,155 @@ library
20272027
''');
20282028
}
20292029

2030+
test_class_constructor_initializers_field_stringInterpolation_expression() async {
2031+
var library = await buildLibrary(r'''
2032+
class C {
2033+
final f;
2034+
const C() : f = '${42}';
2035+
}
2036+
''');
2037+
checkElementText(library, r'''
2038+
library
2039+
reference: <testLibrary>
2040+
fragments
2041+
#F0 <testLibraryFragment>
2042+
element: <testLibrary>
2043+
classes
2044+
#F1 class C @6
2045+
element: <testLibrary>::@class::C
2046+
fields
2047+
#F2 f @18
2048+
element: <testLibrary>::@class::C::@field::f
2049+
constructors
2050+
#F3 const new
2051+
element: <testLibrary>::@class::C::@constructor::new
2052+
typeName: C
2053+
typeNameOffset: 29
2054+
getters
2055+
#F4 synthetic f
2056+
element: <testLibrary>::@class::C::@getter::f
2057+
classes
2058+
class C
2059+
reference: <testLibrary>::@class::C
2060+
firstFragment: #F1
2061+
fields
2062+
final f
2063+
reference: <testLibrary>::@class::C::@field::f
2064+
firstFragment: #F2
2065+
type: dynamic
2066+
getter: <testLibrary>::@class::C::@getter::f
2067+
constructors
2068+
const new
2069+
reference: <testLibrary>::@class::C::@constructor::new
2070+
firstFragment: #F3
2071+
constantInitializers
2072+
ConstructorFieldInitializer
2073+
fieldName: SimpleIdentifier
2074+
token: f @35
2075+
element: <testLibrary>::@class::C::@field::f
2076+
staticType: null
2077+
equals: = @37
2078+
expression: StringInterpolation
2079+
elements
2080+
InterpolationString
2081+
contents: ' @39
2082+
InterpolationExpression
2083+
leftBracket: ${ @40
2084+
expression: IntegerLiteral
2085+
literal: 42 @42
2086+
staticType: int
2087+
rightBracket: } @44
2088+
InterpolationString
2089+
contents: ' @45
2090+
staticType: String
2091+
stringValue: null
2092+
getters
2093+
synthetic f
2094+
reference: <testLibrary>::@class::C::@getter::f
2095+
firstFragment: #F4
2096+
returnType: dynamic
2097+
variable: <testLibrary>::@class::C::@field::f
2098+
''');
2099+
}
2100+
2101+
test_class_constructor_initializers_field_stringInterpolation_identifier() async {
2102+
var library = await buildLibrary(r'''
2103+
class C {
2104+
final f;
2105+
const C(int x) : f = '$x';
2106+
}
2107+
''');
2108+
checkElementText(library, r'''
2109+
library
2110+
reference: <testLibrary>
2111+
fragments
2112+
#F0 <testLibraryFragment>
2113+
element: <testLibrary>
2114+
classes
2115+
#F1 class C @6
2116+
element: <testLibrary>::@class::C
2117+
fields
2118+
#F2 f @18
2119+
element: <testLibrary>::@class::C::@field::f
2120+
constructors
2121+
#F3 const new
2122+
element: <testLibrary>::@class::C::@constructor::new
2123+
typeName: C
2124+
typeNameOffset: 29
2125+
formalParameters
2126+
#F4 x @35
2127+
element: <testLibrary>::@class::C::@constructor::new::@formalParameter::x
2128+
getters
2129+
#F5 synthetic f
2130+
element: <testLibrary>::@class::C::@getter::f
2131+
classes
2132+
class C
2133+
reference: <testLibrary>::@class::C
2134+
firstFragment: #F1
2135+
fields
2136+
final f
2137+
reference: <testLibrary>::@class::C::@field::f
2138+
firstFragment: #F2
2139+
type: dynamic
2140+
getter: <testLibrary>::@class::C::@getter::f
2141+
constructors
2142+
const new
2143+
reference: <testLibrary>::@class::C::@constructor::new
2144+
firstFragment: #F3
2145+
formalParameters
2146+
#E0 requiredPositional x
2147+
firstFragment: #F4
2148+
type: int
2149+
constantInitializers
2150+
ConstructorFieldInitializer
2151+
fieldName: SimpleIdentifier
2152+
token: f @40
2153+
element: <testLibrary>::@class::C::@field::f
2154+
staticType: null
2155+
equals: = @42
2156+
expression: StringInterpolation
2157+
elements
2158+
InterpolationString
2159+
contents: ' @44
2160+
InterpolationExpression
2161+
leftBracket: $ @45
2162+
expression: SimpleIdentifier
2163+
token: x @46
2164+
element: <testLibrary>::@class::C::@constructor::new::@formalParameter::x
2165+
staticType: int
2166+
InterpolationString
2167+
contents: ' @47
2168+
staticType: String
2169+
stringValue: null
2170+
getters
2171+
synthetic f
2172+
reference: <testLibrary>::@class::C::@getter::f
2173+
firstFragment: #F5
2174+
returnType: dynamic
2175+
variable: <testLibrary>::@class::C::@field::f
2176+
''');
2177+
}
2178+
20302179
test_class_constructor_initializers_field_withParameter() async {
20312180
var library = await buildLibrary('''
20322181
class C {

0 commit comments

Comments
 (0)