-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add --no-implicit-dynamic flag to analyzer #24267
Comments
Yes, please! However, it would be easier to maintain the specified language semantics if On Wed, Sep 2, 2015 at 10:26 AM, Florian Loitsch notifications@github.com
Erik Ernst - Google Danmark ApS |
How can the analyzer affect the specified language semantics? I don't see the annotation in the blog entry. The analyzer/IDE should tell the user when it cannot infer a specific type (at least when it could lead to a NSM) and require the least amount of code to get to a clean state. This is different from strong mode which follows strict rules. The analyzer can be much more sophisticated (in the same way that dart2js' type inference propagates types much further than the strong-mode rules could ever specify). |
On Wed, Sep 2, 2015 at 1:26 PM, Florian Loitsch notifications@github.com
But I think that inferring types for Dart that do not correspond to the
we should either infer
In order to be able to promise "no NSM" we need a suitable invariant on the
The instance of
best regards, Erik Ernst - Google Danmark ApS |
There is already too much noise, but to clarify my request: I would be happy if the analyzer furthermore inferred a new type for every assignment (but that's not a requirement and probably makes the reporting harder).
|
This seems like a worthwhile idea, but I don't think either of these claims are true, unless you propose to change the type system:
The program attached below illustrates this. It is fully annotated - there are no variables or expressions of type dynamic anywhere in the program, it passes the analyzer with no warnings, and yet refactoring based on the types will change the production mode semantics. Changing the name of the A.foo method will introduce a NSM error (while preserving the "no-dynamic" property). Changing the name of the B.foo method will also introduce a NSM error. Changing the name of one of these methods to something that is already implemented by the other class could introduce other arbitrary changes in behavior. This program does throw in checked mode, but if these types were the result of inference (rather than being fully annotated), then the code would run fine in checked mode as well, but again, refactoring would change the semantics. // This program has no expressions or variables of type dynamic.
class A {
void foo() => print("A's foo");
}
class B {
void foo() => print("B's foo");
}
typedef A V2A();
typedef B V2B();
typedef Object V2O();
// The static type of f() is A, but B.foo can reach this call site.
void callsAFoo(V2A f) => f().foo();
void mixesThingsUp(V2O f) => callsAFoo(f);
void losesACallToBFoo(V2B f) => mixesThingsUp(f);
B mkB() => new B();
void main() {
losesACallToBFoo(mkB);
} |
Sorry about the additional noise, but it's just too tempting to add a Using the very flexible notion of function type subtyping it is even OK to // This program has no expressions or variables of type dynamic. class B { typedef A V2A(); // The static type of f() is A, but B.foo can reach this call site. Object mkB() => new B(); void main() { The dartanalyzer is happy, checked mode execution is happy, and we still On Wed, Sep 2, 2015 at 6:38 PM, Leaf Petersen notifications@github.com
Erik Ernst - Google Danmark ApS |
OMG YES. :) |
See also: dart-archive/dev_compiler#363 |
(Labeled strong-mode as that's where we're likely to implement this first.) |
Please create a different issue for strong-mode. |
I've opened #25573 for this feature in strong mode. It's been an oft-requested feature, so it's likely to happen there. :) |
It's fine to ensure that this works correctly with strong mode, but it should be possible to specify the option in the absence of strong mode. |
I've removed the tag, sorry about causing confusion. (I'd tagged it as analyzer-strong-mode so we could find it in our hotlist, as we're likely to implement it. For example, that's how we've been tracking the generic method prototype work. Definitely didn't mean to imply that it was a strong-mode exclusive feature. Anyway, sorry about that--I think everything's back how it was, hopefully no harm done :) ) |
If this was implemented for the Dart 1 type system, wouldn't it reject most programs? Dart 1 has no inference so even something like |
Ah I see inference is requested (#24267 (comment)) ... that makes sense, but it probably needs to be specified how the inference should work (e.g. here is where we describe inference for strong mode: https://github.com/dart-lang/dev_compiler/blob/master/doc/STATIC_SAFETY.md). Anyway the reason I asked: in the process of addressing #25573, I can allow the flag to be specified regardless of strong mode, but I'm not sure it will be very useful without strong mode's type inference. |
I don't think there's any value in supporting it in non-strong mode. If it's more work to prevent using it in non-strong mode, then I wouldn't worry about allowing it. But I wouldn't suggest spending any extra effort to support no implicit dynamic outside of strong mode. |
This can be closed, right? E.g., for Dart VM version: 2.0.0-dev.26.0:
cc @kwalrath |
Yes, thanks for noticing and letting us know. |
It would be nice to have a --no-implicit-dynamic flag on the analyzer. It should give a warning when the analyzer can't statically infer the type of a "var" (or missing type). This would be equivalent to C#'s --no-implicit-any [0].
The most important property of this flag should be that refactorings are guaranteed to find all uses of a class or a function. Furthermore, there should be no NSM errors (except for null-pointer exceptions).
Examples:
[0] http://blogs.msdn.com/b/typescript/archive/2013/08/06/announcing-0-9-1.aspx
The text was updated successfully, but these errors were encountered: