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

Fixed double quotes, added override annotation #2592

Merged
merged 4 commits into from
Aug 28, 2020
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
6 changes: 6 additions & 0 deletions examples/strong/lib/animal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ class Animal {

// #docregion HoneyBadger
class HoneyBadger extends Animal {
@override
void chase(Animal a) {/* ... */}

@override
HoneyBadger get parent => ellipsis();
}
// #enddocregion HoneyBadger

// #docregion chase-Object
class HoneyBadger1 extends Animal {
@override
void chase(Object a) {/* ... */}

@override
Animal get parent => ellipsis();
}
// #enddocregion chase-Object
Expand Down
8 changes: 4 additions & 4 deletions examples/strong/lib/strong_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void _miscDeclAnalyzedButNotTested() {
void main() {
var list = [];
list.add(1);
list.add("2");
list.add('2');
// ignore_for_file: stable, dev, argument_type_not_assignable
printInts(list); //!analysis-issue
}
Expand Down Expand Up @@ -77,15 +77,15 @@ void _miscDeclAnalyzedButNotTested() {

{
// #docregion local-var-type-inference-error
var x = 3; // x is inferred as an int
var x = 3; // x is inferred as an int.
// ignore_for_file: stable, dev, invalid_assignment
x = 4.0; //!analysis-issue
// #enddocregion local-var-type-inference-error
}

{
// #docregion local-var-type-inference-ok
num y = 3; // a num can be double or int
num y = 3; // A num can be double or int.
y = 4.0;
// #enddocregion local-var-type-inference-ok
}
Expand All @@ -98,7 +98,7 @@ void _miscDeclAnalyzedButNotTested() {
// Inferred as if you wrote <double>[3.0].
var listOfDouble = [3.0];

// Inferred as Iterable<int>
// Inferred as Iterable<int>.
var ints = listOfDouble.map((x) => x.toInt());
// #enddocregion type-arg-inference

Expand Down
20 changes: 15 additions & 5 deletions src/_guides/language/type-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void printInts(List<int> a) => print(a);
void main() {
var list = [];
list.add(1);
list.add("2");
list.add('2');
printInts([!list!]);
}
{% endprettify %}
Expand Down Expand Up @@ -155,15 +155,21 @@ of Animal), but an unrelated type is not allowed.
<?code-excerpt "strong/lib/animal.dart (HoneyBadger)" replace="/(\w+)(?= get)/[!$&!]/g"?>
{% prettify dart tag=pre+code %}
class HoneyBadger extends Animal {
@override
void chase(Animal a) { ... }

@override
[!HoneyBadger!] get parent => ...
}
{% endprettify %}

{:.fails-sa}
{% prettify dart tag=pre+code %}
class HoneyBadger extends Animal {
@override
void chase(Animal a) { ... }

@override
[!Root!] get parent => ...
}
{% endprettify %}
Expand Down Expand Up @@ -198,7 +204,10 @@ It's OK to override the `chase()` method to take anything (Object).
<?code-excerpt "strong/lib/animal.dart (chase-Object)" replace="/Object/[!$&!]/g"?>
{% prettify dart tag=pre+code %}
class HoneyBadger extends Animal {
@override
void chase([!Object!] a) { ... }

@override
Animal get parent => ...
}
{% endprettify %}
Expand All @@ -211,6 +220,7 @@ from Animal to Mouse, a subclass of Animal.
class Mouse extends Animal {...}

class Cat extends Animal {
@override
void chase([!Mouse!] x) { ... }
}
{% endprettify %}
Expand All @@ -220,7 +230,7 @@ a cat and send it after an alligator:

{% prettify dart tag=pre+code %}
Animal a = Cat();
a.chase([!Alligator!]()); // Not type safe or feline safe
a.chase([!Alligator!]()); // Not type safe or feline safe.
{% endprettify %}

### Don't use a dynamic list as a typed list
Expand Down Expand Up @@ -323,14 +333,14 @@ If so, you can add a type annotation.
{:.fails-sa}
<?code-excerpt "strong/lib/strong_analysis.dart (local-var-type-inference-error)"?>
{% prettify dart tag=pre+code %}
var x = 3; // x is inferred as an int
var x = 3; // x is inferred as an int.
x = 4.0;
{% endprettify %}

{:.passes-sa}
<?code-excerpt "strong/lib/strong_analysis.dart (local-var-type-inference-ok)"?>
{% prettify dart tag=pre+code %}
num y = 3; // a num can be double or int
num y = 3; // A num can be double or int.
y = 4.0;
{% endprettify %}

Expand All @@ -352,7 +362,7 @@ List<int> listOfInt = [];
// Inferred as if you wrote <double>[3.0].
var listOfDouble = [3.0];

// Inferred as Iterable<int>
// Inferred as Iterable<int>.
var ints = listOfDouble.map((x) => x.toInt());
{% endprettify %}

Expand Down