Skip to content

implicit-downcasts in analysis_options doesn't work #27622

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

Closed
nex3 opened this issue Oct 19, 2016 · 15 comments
Closed

implicit-downcasts in analysis_options doesn't work #27622

nex3 opened this issue Oct 19, 2016 · 15 comments
Labels
devexp-command Issues with the command-line dartanalyzer tool legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@nex3
Copy link
Member

nex3 commented Oct 19, 2016

If I have the following .analysis_options file:

analyzer:
  strong-mode:
  - implicit-downcasts: false
  - implicit-dynamic: false

and the following Dart file (taken from this example):

// test.dart

void main() {
  Object o = new Object();
  String s = o;  // Implicit downcast
  String s2 = s.substring(1);
}

and I run dartanalyzer test.dart, it only reports:

[hint] The value of the local variable 's2' is not used

The same is true if I run dartanalyzer --strong --no-implicit-casts test.dart. However, if I delete .analysis_options and run dartanalyzer --strong --no-implicit-casts test.dart, I get:

[error] A value of type 'Object' cannot be assigned to a variable of type 'String'
[hint] The value of the local variable 's2' is not used

I've tested this against Dart 1.20.1 and 1.19.0. I think the implicit-dynamic flag has the same issue, but I don't know of a simple file to test it on.

@nex3 nex3 added legacy-area-analyzer Use area-devexp instead. devexp-command Issues with the command-line dartanalyzer tool analyzer-strong-mode type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 19, 2016
@jmesserly
Copy link

I believe you're looking for implicit-casts: false

@nex3
Copy link
Member Author

nex3 commented Oct 19, 2016

That's not what the docs say...

@nex3
Copy link
Member Author

nex3 commented Oct 19, 2016

Even if I change implicit-downcasts to implicit-casts in the analysis options file, the results are the same.

@bwilkerson bwilkerson added the P2 A bug or feature request we're likely to work on label Oct 19, 2016
@jmesserly
Copy link

That's not what the docs say...

@Sfshaza - where would the best place to be for filing a documentation bug? The flag has always been called implicit-casts (https://github.com/dart-lang/dev_compiler/blob/master/doc/STATIC_SAFETY.md#disable-implicit-casts, https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/src/task/options.dart#L71)

@nex3 -- does it behave any better if you restart analysis server? We've seen bugs in the past where e.g. strong-mode will not be enabled correctly until a restart.

@nex3
Copy link
Member Author

nex3 commented Oct 19, 2016

I'm not using the server, I'm just using the CLI.

@jmesserly
Copy link

Oh. I'm not familiar with under what conditions the CLI will use analysis_options. Does strong mode seem to be working at all?

@nex3
Copy link
Member Author

nex3 commented Oct 19, 2016

I'm not sure. What's a good test case for that?

@jmesserly
Copy link

class C {
  int x() => 0;
}
class D extends C {
  Object x() => 'hi'; // strong mode: invalid override
}

@jmesserly
Copy link

@nex3 could this be the bug you are seeing: #26959

@nex3
Copy link
Member Author

nex3 commented Oct 19, 2016

class C {
  int x() => 0;
}
class D extends C {
  Object x() => 'hi'; // strong mode: invalid override
}

If I analyze this with dartanalyzer and the .analysis_options file listed above, it emits no errors. Same if I replace implicit-downcasts with implicit-casts.

@jmesserly
Copy link

yeah, that means it's not running in strong mode. I believe you're seeing #26959 -- Analyzer CLI does not use analysis_options

@nex3
Copy link
Member Author

nex3 commented Oct 19, 2016

I don't think that's it—I'm analyzing files, not directories, and if I write

analyzer:
  strong-mode: true

strong mode works fine.

@jmesserly
Copy link

jmesserly commented Oct 19, 2016

this works for me:

analyzer:
  strong-mode:
    implicit-casts: false
[error] A value of type 'Object' can't be assigned to a variable of type 'String'. 

the problem is the leading "-", it's a YAML map not a list.
This was noted in the docs I wrote, so it looks like this is a problem with the live documentation.

Move this to https://github.com/dart-lang/site-www/issues?

@bwilkerson
Copy link
Member

dartanalyzer, wrongly in my opinion, is sensitive to the current working directory. I think this sometimes causes problems with discovery of options files. I'm not sure that's what's happening in this case, though.

@jmesserly
Copy link

I believe this has been moved to dart-lang/site-www#161. thanks @nex3 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-command Issues with the command-line dartanalyzer tool legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants