Skip to content

Commit

Permalink
Fixed "type 'SimpleIdentifierImpl' is not a subtype of type 'Property…
Browse files Browse the repository at this point in the history
…Access' in type cast (#2318)

fixes #2313
  • Loading branch information
rrousselGit authored Mar 13, 2023
1 parent 848559e commit c62ecf2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/riverpod_analyzer_utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Added `providerForType` TypeChecker for `ProviderFor` annotation
- Generated providers inside `.g.dart` no-longer are incorrectly parsed as legacy providers.
- Fixed "type 'SimpleIdentifierImpl' is not a subtype of type 'PropertyAccess' in type cast"

## 0.1.4 - 2023-03-10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ class LegacyProviderDeclaration extends RiverpodAst
}
}

final modifier = initializer.function as PropertyAccess;
final modifier = initializer.function;
if (modifier is! PropertyAccess) return null;

decodeIdentifier(modifier.propertyName);
decodeTarget(modifier.target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,46 @@ import 'analyser_test_utils.dart';

void main() {
group('LegacyProviderDefinition.parse', () {
testSource(
'Handles unsupported function expressions',
source: '''
import 'package:riverpod/riverpod.dart';
final provider = Provider<int>((ref) => 0);
Provider<int> create() => Provider((ref) => 0);
final unknown = create();
class Callbable {
Provider<int> call() => Provider((ref) => 0);
}
abstract class A {
static Provider<int> create() => Provider((ref) => 0);
static final callable = Callbable();
}
final unknown2 = A.create();
final unknown3 = A.callable();
final unknown4 = (() => 42)();
Provider<int> Function() get getter => () => Provider((ref) => 0);
final unknown5 = getter();
''',
(resolver) async {
// Regression test for https://github.com/rrousselGit/riverpod/issues/2313
final result = await resolver.resolveRiverpodAnalyssiResult();

expect(result.legacyProviderDeclarations, hasLength(1));
expect(result.generatorProviderDeclarations, isEmpty);
expect(
result.legacyProviderDeclarations.first.node.toSource(),
'provider = Provider<int>((ref) => 0)',
);
},
);

testSource('Does not try to parse generated providers',
runGenerator: true, source: '''
import 'package:riverpod/riverpod.dart';
Expand Down
1 change: 1 addition & 0 deletions packages/riverpod_lint/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased fix

- No-longer throw "Bad state: Too many elements"
- Fixed "type 'SimpleIdentifierImpl' is not a subtype of type 'PropertyAccess' in type cast"

## 1.1.5 - 2023-03-10

Expand Down

0 comments on commit c62ecf2

Please sign in to comment.