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

Strong mode code excerpt tests for fix-it page #603

Merged
merged 5 commits into from
Feb 23, 2018

Conversation

chalin
Copy link
Contributor

@chalin chalin commented Feb 22, 2018

Contributes to #407

Staged at https://dartlang-org-staging-0.firebaseapp.com/guides/language/sound-problems


Each of the static warnings/errors now has:

  • An "Example" subsection
  • A "Fix" subsection
  • Actual analyzer error messages (excerpt from captured analyzer output).

E.g.,

screen shot 2018-02-22 at 18 07 50

@chalin chalin added infra.structure Relates to the tools that create dart.dev SoundDart fix.examples Adds or changes example test.general Relates to unit, integration, perf testing labels Feb 22, 2018
@chalin chalin requested a review from kwalrath February 22, 2018 23:07
@googlebot googlebot added the cla: yes Contributor has signed the Contributor License Agreement label Feb 22, 2018
@chalin chalin force-pushed the chalin-strong-mode-common-problems-0221 branch from 0fb637b to 8cca216 Compare February 22, 2018 23:19
Copy link
Contributor

@kwalrath kwalrath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few possible issues and suggestions, but in general this looks great. Thanks for improving the page, as well as making sure the code will be tested!

{% comment %}
NOTE TO Kathy: I don't think that we should recommend use of dynamic in this case,
so I'm commenting this out. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a similar case where you would want dynamic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While not for this specific example, there are similar situations where we'd like to be able to write a union type but can't. I'll tweak the code and include the example using dynamic.

NOTE TO Kathy: I think that we should consider renaming this section. How about
<a id ="assigning-mismatched-types"></a>
### Unexpected collection element type

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

error • The getter 'context2D' isn't defined for the class 'Element' • undefined_getter
```

#### **Fix**: Replace the definition of the member with an explicit type declaration or a downcast
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not boldface "Fix" (global).

class Animal {
void chase(Animal x) {}
void chase(Animal x) { ... }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to use the NumberAdder example instead of Animal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but why do you feel it would be better? (I'll leave the Animal hierarchy for now.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the link is from the section that has the NumberAdder example. It's a bit jarring to switch to another example.


This sometimes happens when you create a simple dynamic collection
and the analyzer Dart infers the type in a way you didn't expect.
and the analyzer infers the type in a way you didn't expect.
When you later add values of a different type,
the analyzer produces a warning.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning -> error

@@ -175,45 +208,56 @@ to specify a type. For more information, see
[Missing type arguments](#missing-type-arguments).
</aside>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above, the note says "warning" but should say "error" or "issue".

For example, the following code initializes a map with several
(String, integer) pairs. The analyzer infers that map to be of type
The following code initializes a map with several
(String, int) pairs. The analyzer infers that map to be of type
`<String, int>` but the code assumes `<String, dynamic>`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue that it assumes <String, num>, which matches the suggested fix. Maybe:

...<String, int>, but the code seems to assume either <String, dynamic> or <String, num>.

However, in Dart 2 passing something other than `dynamic` (or another _top_
type, such as `Object`, or a specific bottom type, such as `Null`) fails at
compile-time (called `uses_dynamic_as_bottom`):
compile-time.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a warning, not an error, so does it really fail?


One fix could be, if possible, typing `Filter` as `Filter<T>`:
When possible, fix this error by adding type parameters:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix this error -> avoid this warning
?

different than the variable's static type. Like most modern statically
typed langauges, Dart accomplishes this with a mixture of static
typed langauges, Dart accomplishes this with a combination of static
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

langauges -> languages

@chalin chalin merged commit 048c6d3 into master Feb 23, 2018
@chalin chalin deleted the chalin-strong-mode-common-problems-0221 branch February 23, 2018 14:12
chalin added a commit that referenced this pull request Feb 23, 2018
chalin added a commit that referenced this pull request Feb 23, 2018
@atsansone atsansone added dev.null-safety Relates to transforming or migrating Dart code to sound null safety and removed SoundDart labels Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Contributor has signed the Contributor License Agreement dev.null-safety Relates to transforming or migrating Dart code to sound null safety fix.examples Adds or changes example infra.structure Relates to the tools that create dart.dev test.general Relates to unit, integration, perf testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants