Skip to content

Commit

Permalink
Improve error output for types with type parameters
Browse files Browse the repository at this point in the history
Helps with #713
  • Loading branch information
kevmoo committed Sep 10, 2020
1 parent d09c99f commit ae72259
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions json_serializable/lib/src/helper_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ String typeToCode(DartType type) {
final typeArgumentsCode = typeArguments.map(typeToCode).join(', ');
return '${type.element.name}<$typeArgumentsCode>';
}
} else if (type is TypeParameterType) {
return '${type.getDisplayString()} (type parameter)';
}
throw UnimplementedError('(${type.runtimeType}) $type');
}
1 change: 1 addition & 0 deletions json_serializable/test/json_serializable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const _expectedAnnotatedTests = [
'InvalidChildClassFromJson3',
'InvalidFromFunc2Args',
'InvalidToFunc2Args',
'Issue713',
'JsonConverterCtorParams',
'JsonConverterDuplicateAnnotations',
'JsonConverterNamedCtor',
Expand Down
10 changes: 10 additions & 0 deletions json_serializable/test/src/generic_test_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

part of '_json_serializable_test_input.dart';

@ShouldThrow(
'Could not generate `fromJson` code for `result` because of type '
'`TResult (type parameter)`.\n'
'None of the provided `TypeHelper` instances support the defined type.',
)
@JsonSerializable()
class Issue713<TResult> {
List<TResult> result;
}

@ShouldGenerate(r'''
GenericClass<T, S> _$GenericClassFromJson<T extends num, S>(
Map<String, dynamic> json) {
Expand Down

0 comments on commit ae72259

Please sign in to comment.