Skip to content

Commit f36a637

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Fix for FieldElementImpl.type derivation.
https://dart-review.googlesource.com/c/sdk/+/439040 had a small bug with using less precise type from inherited setter, even though there is a declared getter in the this class. Change-Id: Ib136d370002cca23707bf62b681a01b0c6ac75cc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439340 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 79a7a7f commit f36a637

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ class InstanceMemberInferrer {
227227
var valueType = combinedGetterType();
228228
parameter.type = valueType;
229229
var fieldElement = accessor.element.variable3 as FieldElementImpl;
230-
fieldElement.type = valueType;
230+
if (fieldElement.getter2 == null) {
231+
fieldElement.type = valueType;
232+
fieldElement.firstFragment.type = valueType;
233+
}
231234
return;
232235
}
233236

pkg/analyzer/test/src/summary/top_level_inference_test.dart

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9552,6 +9552,94 @@ library
95529552
''');
95539553
}
95549554

9555+
test_instanceField_fromGetter_hasGetterWithType_hasSetterNoType() async {
9556+
configuration.withConstructors = false;
9557+
var library = await _encodeDecodeLibrary(r'''
9558+
abstract class A {
9559+
num get foo;
9560+
}
9561+
class B implements A {
9562+
int get foo => 0;
9563+
set foo(value) {}
9564+
}
9565+
''');
9566+
checkElementText(library, r'''
9567+
library
9568+
reference: <testLibrary>
9569+
fragments
9570+
#F0 <testLibraryFragment>
9571+
element: <testLibrary>
9572+
classes
9573+
#F1 class A @15
9574+
element: <testLibrary>::@class::A
9575+
fields
9576+
#F2 synthetic foo
9577+
element: <testLibrary>::@class::A::@field::foo
9578+
getters
9579+
#F3 foo @29
9580+
element: <testLibrary>::@class::A::@getter::foo
9581+
returnType: num
9582+
#F4 class B @42
9583+
element: <testLibrary>::@class::B
9584+
fields
9585+
#F5 synthetic foo
9586+
element: <testLibrary>::@class::B::@field::foo
9587+
getters
9588+
#F6 foo @69
9589+
element: <testLibrary>::@class::B::@getter::foo
9590+
returnType: int
9591+
setters
9592+
#F7 foo @85
9593+
element: <testLibrary>::@class::B::@setter::foo
9594+
formalParameters
9595+
#F8 value @89
9596+
element: <testLibrary>::@class::B::@setter::foo::@formalParameter::value
9597+
classes
9598+
abstract class A
9599+
reference: <testLibrary>::@class::A
9600+
firstFragment: #F1
9601+
fields
9602+
synthetic foo
9603+
reference: <testLibrary>::@class::A::@field::foo
9604+
firstFragment: #F2
9605+
type: num
9606+
getter: <testLibrary>::@class::A::@getter::foo
9607+
getters
9608+
abstract foo
9609+
reference: <testLibrary>::@class::A::@getter::foo
9610+
firstFragment: #F3
9611+
returnType: num
9612+
variable: <testLibrary>::@class::A::@field::foo
9613+
class B
9614+
reference: <testLibrary>::@class::B
9615+
firstFragment: #F4
9616+
interfaces
9617+
A
9618+
fields
9619+
synthetic foo
9620+
reference: <testLibrary>::@class::B::@field::foo
9621+
firstFragment: #F5
9622+
type: int
9623+
getter: <testLibrary>::@class::B::@getter::foo
9624+
setter: <testLibrary>::@class::B::@setter::foo
9625+
getters
9626+
foo
9627+
reference: <testLibrary>::@class::B::@getter::foo
9628+
firstFragment: #F6
9629+
returnType: int
9630+
variable: <testLibrary>::@class::B::@field::foo
9631+
setters
9632+
foo
9633+
reference: <testLibrary>::@class::B::@setter::foo
9634+
firstFragment: #F7
9635+
formalParameters
9636+
#E0 requiredPositional hasImplicitType value
9637+
firstFragment: #F8
9638+
type: num
9639+
returnType: void
9640+
''');
9641+
}
9642+
95559643
test_instanceField_fromGetter_multiple_different() async {
95569644
var library = await _encodeDecodeLibrary(r'''
95579645
abstract class A {

0 commit comments

Comments
 (0)