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
12 changes: 6 additions & 6 deletions json_serializable/lib/src/decode_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ mixin DecodeHelper implements HelperCore {
///
/// To improve the error details, [unavailableReasons] is checked for the
/// unavailable constructor parameter. If the value is not `null`, it is
/// included in the [UnsupportedError] message.
/// included in the [UnsupportedError] message; otherwise a default explanation
/// is provided.
///
/// [writableFields] are also populated, but only if they have not already
/// been defined by a constructor parameter with the same name.
Expand Down Expand Up @@ -336,11 +337,10 @@ _ConstructorData _writeConstructorInvocation(
'Cannot populate the required constructor '
'argument: ${arg.name}.';

final additionalInfo = unavailableReasons[arg.name];

if (additionalInfo != null) {
msg = '$msg $additionalInfo';
}
final additionalInfo =
unavailableReasons[arg.name] ??
'It does not correspond to any field or getter on the class.';
msg = '$msg $additionalInfo';

throw InvalidGenerationSourceError(msg, element: ctor);
}
Expand Down
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 @@ -157,6 +157,7 @@ const _expectedAnnotatedTests = {
'Reproduce869NullableGenericTypeWithDefault',
'SameCtorAndJsonKeyDefaultValue',
'SetSupport',
'StandaloneCtorParamClass',
'SubclassedJsonKey',
'SubType',
'SubTypeWithAnnotatedFieldOverrideExtends',
Expand Down
12 changes: 12 additions & 0 deletions json_serializable/test/src/_json_serializable_test_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,18 @@ class PrivateFieldCtorClass {
PrivateFieldCtorClass(this._privateField);
}

@ShouldThrow(
'Cannot populate the required constructor argument: '
'standaloneParam. It does not correspond to any field or getter on the '
'class.',
element: 'new',
)
@JsonSerializable()
class StandaloneCtorParamClass {
// ignore: avoid_unused_constructor_parameters
StandaloneCtorParamClass({required int standaloneParam});
}

@ShouldThrow(
'Error with `@JsonKey` on the `field` field. '
'Cannot set both `disallowNullValue` and `includeIfNull` to `true`. '
Expand Down
Loading