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

Remove superseded sound problems page #6484

Merged
merged 2 commits into from
Mar 12, 2025
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
3 changes: 1 addition & 2 deletions examples/type_system/analyzer-results-beta.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ Analyzing type_system...
error - lib/strong_analysis.dart:109:23 - A value of type 'String' can't be assigned to a variable of type 'double'. Try changing the type of the variable, or casting the right-hand type to 'double'. - invalid_assignment
error - lib/strong_analysis.dart:121:19 - A value of type 'Cat' can't be assigned to a variable of type 'MaineCoon'. Try changing the type of the variable, or casting the right-hand type to 'MaineCoon'. - invalid_assignment
error - lib/strong_analysis.dart:148:24 - A value of type 'List<Animal>' can't be assigned to a variable of type 'List<Cat>'. Try changing the type of the variable, or casting the right-hand type to 'List<Cat>'. - invalid_assignment
error - test/strong_test.dart:120:26 - A value of type 'dynamic' can't be assigned to a variable of type 'List<String>'. Try changing the type of the variable, or casting the right-hand type to 'List<String>'. - invalid_assignment

16 issues found.
15 issues found.
3 changes: 1 addition & 2 deletions examples/type_system/analyzer-results-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ Analyzing type_system...
error - lib/strong_analysis.dart:109:23 - A value of type 'String' can't be assigned to a variable of type 'double'. Try changing the type of the variable, or casting the right-hand type to 'double'. - invalid_assignment
error - lib/strong_analysis.dart:121:19 - A value of type 'Cat' can't be assigned to a variable of type 'MaineCoon'. Try changing the type of the variable, or casting the right-hand type to 'MaineCoon'. - invalid_assignment
error - lib/strong_analysis.dart:148:24 - A value of type 'List<Animal>' can't be assigned to a variable of type 'List<Cat>'. Try changing the type of the variable, or casting the right-hand type to 'List<Cat>'. - invalid_assignment
error - test/strong_test.dart:120:26 - A value of type 'dynamic' can't be assigned to a variable of type 'List<String>'. Try changing the type of the variable, or casting the right-hand type to 'List<String>'. - invalid_assignment

16 issues found.
15 issues found.
3 changes: 1 addition & 2 deletions examples/type_system/analyzer-results-stable.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ Analyzing type_system...
error - lib/strong_analysis.dart:109:23 - A value of type 'String' can't be assigned to a variable of type 'double'. Try changing the type of the variable, or casting the right-hand type to 'double'. - invalid_assignment
error - lib/strong_analysis.dart:121:19 - A value of type 'Cat' can't be assigned to a variable of type 'MaineCoon'. Try changing the type of the variable, or casting the right-hand type to 'MaineCoon'. - invalid_assignment
error - lib/strong_analysis.dart:148:24 - A value of type 'List<Animal>' can't be assigned to a variable of type 'List<Cat>'. Try changing the type of the variable, or casting the right-hand type to 'List<Cat>'. - invalid_assignment
error - test/strong_test.dart:120:26 - A value of type 'dynamic' can't be assigned to a variable of type 'List<String>'. Try changing the type of the variable, or casting the right-hand type to 'List<String>'. - invalid_assignment

16 issues found.
15 issues found.
90 changes: 1 addition & 89 deletions examples/type_system/test/strong_test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// ignore_for_file: unused_local_variable, strict_raw_type
// ignore_for_file: unused_local_variable
import 'package:test/test.dart';

import 'package:type_system_examples/animal.dart';
import 'package:type_system_examples/bounded/my_collection.dart';

Matcher _throwsA<T>(String msg) => throwsA(
allOf(TypeMatcher<T>(), predicate((e) => e.toString().contains(msg))),
Expand Down Expand Up @@ -36,92 +35,5 @@ void main() {
const msg = "type 'List<Dog>' is not a subtype of type 'List<Cat>'";
expect(main, _throwsA<TypeError>(msg));
});

test('downcast check fails', () {
void downcastCheck() {
// #docregion fail-downcast-check
assumeStrings(<int>[1, 2, 3]);
// #enddocregion fail-downcast-check
}

// #docregion downcast-check-msg
const msg = "type 'List<int>' is not a subtype of type 'List<String>'";
// #enddocregion downcast-check-msg
expect(downcastCheck, _throwsA<TypeError>(msg));
});

final expectedOutput = 'a string\n';

test('downcast check ok for <String>[]', () {
void downcastCheck() {
// #docregion typed-list-lit
var list = <String>[];
list.add('a string');
list.add('another');
assumeStrings(list);
// #enddocregion typed-list-lit
}

expect(downcastCheck, prints(expectedOutput));
});

test('downcast check ok for List<String>', () {
void downcastCheck() {
// #docregion typed-list
List<String> list = [];
list.add('a string');
list.add('another');
assumeStrings(list);
// #enddocregion typed-list
}

expect(downcastCheck, prints(expectedOutput));
});

Map<String, dynamic> fetchFromExternalSource() => {
'names': ['a string'],
};

test('downcast check ok: use cast()', () {
void downcastCheck() {
// #docregion cast
Map<String, dynamic> json = fetchFromExternalSource();
var names = json['names'] as List;
assumeStrings(names.cast<String>());
// #enddocregion cast
}

expect(downcastCheck, prints(expectedOutput));
});

test('instantiate-to-bound sanity', () {
final b = B();
expect(b.typeOfS, 'int');
expect(b.typeOfT, 'dynamic');
});

test('instantiate-to-bound fix: add type arg', () {
// #docregion add-type-arg
var c = C<List>([]).collection;
c.add(2);
// #enddocregion add-type-arg
expect(c, [2]);
});
});
}

// #docregion downcast-check
void assumeStrings(dynamic objects) {
// ignore: stable, beta, dev, invalid_assignment
List<String> strings = objects; // Runtime downcast check
String string = strings[0]; // Expect a String value
// #enddocregion downcast-check
print(string);
// #docregion downcast-check
}
// #enddocregion downcast-check

class B<S extends int, T> {
String get typeOfS => '$S';
String get typeOfT => '$T';
}
5 changes: 3 additions & 2 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
{ "source": "/dart-vm{,/**}", "destination": "/server", "type": 301 },
{ "source": "/dart2js-reflection", "destination": "https://github.com/dart-lang/sdk/issues/21654", "type": 301 },
{ "source": "/dartium{,/**}", "destination": "/tools#editors", "type": 301 },
{ "source": "/deprecated/sound-problems", "destination": "/language/type-system", "type": 301 },
{ "source": "/devices", "destination": "/overview#platform", "type": 301 },
{ "source": "/dev{,/**}", "destination": "https://api.dart.dev/dev", "type": 301 },
{ "source": "/diagnostics", "destination": "/tools/diagnostic-messages", "type": 301 },
Expand Down Expand Up @@ -217,7 +218,7 @@
{ "source": "/guides/language/cheatsheet", "destination": "/language", "type": 301 },
{ "source": "/guides/language/coming-from/js-to-dart", "destination": "/resources/coming-from/js-to-dart", "type": 301 },
{ "source": "/guides/language/coming-from/swift-to-dart", "destination": "/resources/coming-from/swift-to-dart", "type": 301 },
{ "source": "/guides/language/common-prob", "destination": "/deprecated/sound-problems", "type": 301 },
{ "source": "/guides/language/common-prob", "destination": "/language/type-system", "type": 301 },
{ "source": "/guides/language/concurrency", "destination": "/language/concurrency", "type": 301 },
{ "source": "/guides/language/effective-dart", "destination": "/effective-dart", "type": 301 },
{ "source": "/guides/language/effective-dart/:page*", "destination": "/effective-dart/:page*", "type": 301 },
Expand All @@ -229,7 +230,7 @@
{ "source": "/guides/language/numbers", "destination": "/resources/language/number-representation", "type": 301 },
{ "source": "/guides/language/sound-dart", "destination": "/language/type-system", "type": 301 },
{ "source": "/guides/language/sound-faq", "destination": "/language/type-system", "type": 301 },
{ "source": "/guides/language/sound-problems", "destination": "/deprecated/sound-problems", "type": 301 },
{ "source": "/guides/language/sound-problems", "destination": "/language/type-system", "type": 301 },
{ "source": "/guides/language/spec", "destination": "/resources/language/spec", "type": 301 },
{ "source": "/guides/language/specifications", "destination": "/resources/language/spec", "type": 301 },
{ "source": "/guides/language/specifications/:page*", "destination": "/resources/language/spec/versions/:page*", "type": 301 },
Expand Down
2 changes: 0 additions & 2 deletions src/_data/sidenav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@
children:
- title: Customizing static analysis
permalink: /tools/analysis
- title: Fixing common type problems
permalink: /deprecated/sound-problems
- title: Fixing type promotion failures
permalink: /tools/non-promotion-reasons
- title: Linter rules
Expand Down
Loading