Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source_gen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.0.2-wip

- Bug fix: fix possible null pointer exception in `TypeChecker.typeNamed` on
invalid code.

## 4.0.1

- Require `analyzer: '>=8.1.1 <9.0.0'`.
Expand Down
4 changes: 3 additions & 1 deletion source_gen/lib/src/type_checker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ class _NameTypeChecker extends TypeChecker {

@override
bool isExactly(Element element) {
final uri = element.library!.uri;
final library = element.library;
if (library == null) return false;
final uri = library.uri;
return element.name == _typeName &&
(_inPackage == null ||
(((uri.scheme == 'dart') == _inSdk) &&
Expand Down
2 changes: 1 addition & 1 deletion source_gen/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: source_gen
version: 4.0.1
version: 4.0.2-wip
description: >-
Source code generation builders and utilities for the Dart build system
repository: https://github.com/dart-lang/source_gen/tree/master/source_gen
Expand Down
8 changes: 8 additions & 0 deletions source_gen/test/type_checker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ void main() {
);
});

group('isExactly', () {
test('should not crash with null library', () {
final element = core.typeProvider.dynamicType.element!;
expect(element.library, isNull);
expect(checkMapMixin().isExactly(element), isFalse);
});
});

group('isExactlyType', () {
test('should not crash with null element', () {
final voidType = core.typeProvider.voidType;
Expand Down