dart-lang / dart-lang/source_gen

ConstantReader.revive() crashes when attempting to revive a type

Open
#411 12 comments 1 reaction 0 assignees View on GitHub
type-bug
Dominant language
Dart
Stars
494
Forks
115
Avg merge
12h 13m
Merged PRs (30d)
3

Description

e.g. Adding a test to constants_test.dart:

```dart
@TypeWrapper(String)
class Example {}

class TypeWrapper {
final Type t;
const TypeWrapper(this.t);
}

test('should not crash when resolving types', () {
expect(typeWrapperConstant.read('t').revive(), isNull /* or anything */)
});
```

throws the following:
```
Bad state: No element
dart:core List.first
package:source_gen/src/constants/revive.dart 97:21 reviveInstance
package:source_gen/src/constants/reader.dart 276:25 _DartObjectConstant.revive
test/constants_test.dart 356:49 main..
```

I don't know what the correct behaviour is, but I know the code should not crash.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the example in test/constants_test.dart and inspect reviveInstance in package:source_gen/src/constants/revive.dart, especially the failing lookup at line 97. Determine the intended result for a Type constant, then add a regression test; done means the test no longer raises Bad state: No element.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.