File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -174,7 +174,17 @@ abstract class TypeChecker {
174174 bool isExactly (Element element);
175175
176176 /// Returns `true` if representing the exact same type as [staticType] .
177- bool isExactlyType (DartType staticType) => isExactly (staticType.element! );
177+ ///
178+ /// This will always return false for types without a backingclass such as
179+ /// `void` or function types.
180+ bool isExactlyType (DartType staticType) {
181+ final element = staticType.element;
182+ if (element != null ) {
183+ return isExactly (element);
184+ } else {
185+ return false ;
186+ }
187+ }
178188
179189 /// Returns `true` if representing a super class of [element] .
180190 ///
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ void main() {
3131 late TypeChecker staticMapMixinChecker;
3232 late TypeChecker staticHashMapChecker;
3333 late TypeChecker staticEnumChecker;
34+ late LibraryElement core;
3435
3536 // Resolved top-level types from package:source_gen.
3637 late InterfaceType staticGenerator;
@@ -45,7 +46,6 @@ void main() {
4546 late InterfaceType staticMyEnumWithMixin;
4647
4748 setUpAll (() async {
48- late LibraryElement core;
4949 late LibraryElement collection;
5050 late LibraryReader sourceGen;
5151 late LibraryElement testSource;
@@ -184,6 +184,17 @@ void main() {
184184 );
185185 });
186186
187+ group (
188+ 'isExactlyType' ,
189+ () {
190+ test ('should not crash with null element' , () {
191+ final voidType = core.typeProvider.voidType;
192+ expect (voidType.element, isNull);
193+ expect (checkMapMixin ().isExactlyType (voidType), isFalse);
194+ });
195+ },
196+ );
197+
187198 group (
188199 '(MapMixin' ,
189200 () {
You can’t perform that action at this time.
0 commit comments