Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: widening return types is not breaking #187

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Version 0.19.1
- fixes widening return types not being detected as a breaking change

## Version 0.19.0
- introduces `force-use-flutter` option for all commands to force dart_apitool to use the `flutter` command.
- extend type usage tracking and fix situations in which types that are used in @visibleForTesting contexts were detected as not exported
Expand Down
12 changes: 1 addition & 11 deletions lib/src/diff/package_api_differ.dart
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,7 @@ class PackageApiDiffer {
newExecutable,
'Return type changed. ${oldExecutable.returnTypeName} -> ${newExecutable.returnTypeName}',
changes,
isCompatibleChange: typeHierarchy.isCompatibleReplacement(
oldTypeIdentifier: TypeIdentifier.fromNameAndLibraryPath(
typeName: oldExecutable.returnTypeName,
libraryPath: oldExecutable.returnTypeFullLibraryName,
),
newTypeIdentifier: TypeIdentifier.fromNameAndLibraryPath(
typeName: newExecutable.returnTypeName,
libraryPath: newExecutable.returnTypeFullLibraryName,
),
isTypePassedIn: false,
),
isCompatibleChange: false,
changeCode: ApiChangeCode.ce09,
isExperimental: isExperimental,
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: dart_apitool
description: A tool to analyze the public API of a package, create a model of it and diff it against another version to check semver.
repository: https://github.com/bmw-tech/dart_apitool

version: 0.19.0-dev
version: 0.19.1-dev

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ void main() {
);
});

test('is no breaking change for function return types', () {
test('is a breaking change for function return types', () {
final functionChange = diffResult.apiChanges
.where((ac) =>
ac.affectedDeclaration?.name.contains('function') ?? false)
.single;
expect(
functionChange.isBreaking,
isFalse,
isTrue,
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ void main() {
isFalse,
);
});

test('detects return type change and is breaking', () {
final localReturnTypeParamChange = diffResult.apiChanges
.where((ac) => ac.affectedDeclaration?.name == 'returnSomeInstance')
.single;
expect(localReturnTypeParamChange.isBreaking, isTrue);
});
});
group('narrowing types', () {
late PackageApiDiffResult diffResult;
Expand Down Expand Up @@ -89,6 +96,13 @@ void main() {
isTrue,
);
});

test('detects return type change and is breaking', () {
final localReturnTypeParamChange = diffResult.apiChanges
.where((ac) => ac.affectedDeclaration?.name == 'returnSomeInstance')
.single;
expect(localReturnTypeParamChange.isBreaking, isTrue);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class ClassA {
void methodUsingLocalType(SomeSubType localTypeParam) {
print(param);
}

SomeSubType returnSomeInstance() {
return SomeSubType();
}
}

class SomeSuperType {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class ClassA {
void methodUsingLocalType(SomeSuperType localTypeParam) {
print(param);
}

SomeSuperType returnSomeInstance() {
return SomeSubType();
}
}

class SomeSuperType {}
Expand Down
Loading