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 sample analysis build jobs #2575

Merged
merged 18 commits into from
Aug 14, 2020
Merged

Fix sample analysis build jobs #2575

merged 18 commits into from
Aug 14, 2020

Conversation

kwalrath
Copy link
Contributor

@kwalrath kwalrath commented Aug 13, 2020

I had to disregard sample analysis (see f5af1bd) to fix the build when 2.9 stable was released.

But the site should always pass static analysis in the stable build, and preferably the beta build as well (#2525).

I'm uploading my work in progress, so @theacodes can (I hope) take it over and actually fix the build.

@googlebot googlebot added the cla: yes Contributor has signed the Contributor License Agreement label Aug 13, 2020
@kwalrath kwalrath marked this pull request as draft August 13, 2020 15:57
@kwalrath
Copy link
Contributor Author

Don't let the Travis build passing fool you... analysis still fails. (I should've updated .travis.yml.) Here's how it fails now: https://travis-ci.org/github/dart-lang/site-www/jobs/717457700.

kwalrath and others added 2 commits August 13, 2020 09:03
This seemed to be broken becuase of a deleted/renamed file (`animal_bad.dart` & `common_problems_analysis.dart`).
@kwalrath
Copy link
Contributor Author

The reason the build is failing is, apparently, that errors can no longer be ignored. There's a discussion at dart-lang/sdk#42977.

@theacodes
Copy link
Contributor

It ain't easy being green. 🐸

@theacodes theacodes marked this pull request as ready for review August 13, 2020 19:52
@theacodes theacodes changed the title WIP: Fix sample analysis Fix sample analysis build jobs Aug 13, 2020
Copy link
Contributor Author

@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.

Some questions, and some places where I'd like to consult with people who've been working on them (Bob for Effective Dart, John for the site infra), but I'm so happy to have this running again!

@@ -1,6 +1,6 @@
void miscDeclAnalyzedButNotTested() {
var fruits = List<String>();
// ignore_for_file: stable, dev, argument_type_not_assignable
// ignore_for_file: stable, dev, argument_type_not_assignable, unused_local_variable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we add beta to this list? Or remove the release names?

(Is "beta" even supported? I don't see examples/strong/analyzer-results-beta.txt in this PR.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure? I can't quite figure out how that works. If there isn't a -beta.txt file it uses analyzer-results.txt, and I think most of the beta files that existed were fine.

@@ -1,18 +1,11 @@
Analyzing analysis_options.yaml, lib, test...
error • 'HoneyBadger.parent' ('Root Function()') isn't a valid override of 'Animal.parent' ('Animal Function()'). • lib/animal_bad.dart:15:12 • invalid_override
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this file different from analyzer-results-stable.txt? If not, then maybe we should remove one of these files and delete "-stable" from the name.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's identical.

@@ -1281,8 +1281,10 @@ num highScore(List<num> scores) {
}
{% endprettify %}

<!-- Q: As of 2.9, this code no longer works.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@munificent opinion?

Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't it work? Because we're getting rid of implicit downcasts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why doesn't it work? Because we're getting rid of implicit downcasts?

Yes, I think so. Here's the message, which complains about highest (an int) being assigned score (a num).

error * A value of type 'num' can't be assigned to a variable of type 'int'. * lib/effective_dart/design_bad.dart:79:38 * invalid_assignment

  num highScore(List<num> scores) {
    var highest = 0;
    for (var score in scores) {
      // ignore: invalid_assignment
      if (score > highest) highest = score;
    }
    return highest;
  }

@@ -1072,8 +1072,10 @@ If a field doesn't depend on any constructor parameters, it can and should be
initialized at its declaration. It takes less code and makes sure you won't
forget to initialize it if the class has multiple constructors.

<!-- Q: As of 2.9, this code no longer works.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@munificent opinion?

Copy link
Member

Choose a reason for hiding this comment

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

I mentioned this elsewhere, but to close the loop here, I think we should make contents non-final (assuming I'm guessing correctly at what no longer works).

{% prettify dart tag=pre+code %}
bool b = [0][0];
{% endprettify %}

With type-safe Dart, the analyzer produces the following error:

{:.console-output}
<?code-excerpt "strong/analyzer-results-stable.txt" retain="/'int' can't be .* 'bool'.*common_problems/"?>
<!-- code-excerpt "strong/analyzer-results-stable.txt" retain="/'int' can't be .* 'bool'.*common_problems/" -->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we uncomment the code-excerpt tag? Otherwise, the analyzer message could change and we wouldn't know.

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem is that since we removed the files that generate those errors, we can't get that error excerpt from those files (same applies to the other comments about this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well drat. I think it's fine for now, but since analysis messages do change, I could file a bug about fixing that.

Or... since analyzer messages are now listed & explained in https://dart.dev/tools/diagnostic-messages, for some messages at least we could have static (not included) text that links to the message description there (in another PR). An advantage of this approach is that if/when the message changes, @bwilkerson has started adding forwarding links to the old links. (See the discussion at #2569.)

@@ -55,9 +54,9 @@ see [Runtime errors](#common-errors-and-warnings).

### Undefined member

<?code-excerpt "strong/analyzer-results-stable.txt" retain="/isn't defined for the type.*common_problems/" replace="/getter/<member\x3E/g; /'\w+'/'...'/g"?>
<!-- code-excerpt "strong/analyzer-results-stable.txt" retain="/isn't defined for the type.*common_problems/" replace="/getter/<member\x3E/g; /'\w+'/'...'/g" -->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we uncomment the code-excerpt? (I have the same question for every other commented-out code-excerpt in this file where we show the error text. :)

src/_guides/language/sound-problems.md Outdated Show resolved Hide resolved
@@ -73,24 +73,6 @@ function analyze_and_test() {
EXPECTED_FILE=$PROJECT_ROOT/analyzer-results.txt
fi
travis_fold start analyzeAndTest.analyze
if [[ -e $EXPECTED_FILE && -z $QUICK ]]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@theacodes
Copy link
Contributor

theacodes commented Aug 14, 2020 via email

@kwalrath
Copy link
Contributor Author

@johnpryan could you approve this? Turns out I shouldn't because it started out as my PR...

@johnpryan
Copy link
Contributor

Sure, taking a look

Copy link
Contributor

@johnpryan johnpryan left a comment

Choose a reason for hiding this comment

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

LGTM. I think we need to adjust our strategy for analyzing "bad" snippets, if we choose to try to analyze them again. It might be reasonable to keep them unanalyzed since we're still analyzing the "good" ones. The downside is that we will be relying on contributors checking the bad snippet if they make a change to the good one.

@@ -7,9 +7,9 @@ int timesTwo(int x) {
int timesFour(int x) => timesTwo(timesTwo(x));

// Functions are objects.
int runTwice(int x, Function f) {
int runTwice(int x, int Function(int) f) {
Copy link
Contributor

Choose a reason for hiding this comment

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

just FYI I just merged a change that moves this snippet into dartpad_picker_main. I created an issue to track: #2581

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants