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

Analyzer does not recognize top-level function as constant. #13179

Closed
lrhn opened this issue Sep 9, 2013 · 7 comments
Closed

Analyzer does not recognize top-level function as constant. #13179

lrhn opened this issue Sep 9, 2013 · 7 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures
Milestone

Comments

@lrhn
Copy link
Member

lrhn commented Sep 9, 2013

Triggering code:

void f([void f([x]) = f]) { print("?");if (f != null) f(null); }

main() {
  f();
  print("ok");
}

This assumes (based on dart2js and dart implementations) that the scope of the default expression "f" will refer to the top-level function.
The analyzer seems to expect it to contain the formal parameter declarations as well (which can never be constant anyway, so it's not useful).

@bwilkerson
Copy link
Member

My understanding of the specification is as follows.

The function 'f' is defined in the library scope and hence is visible on line 4 ("f();") where it is invoked.

The formal parameter scope (nested in the library scope) defines the name 'f'. This is analogous to a local variable, which means that the name of the parameter cannot be used in the default value expression, but could be used by parameters following 'f' (if there were any, which in this case there are not).

Changing this to a language issue for clarification, both of my interpretation of the specification and whether that's how we want the specification to read.


cc @gbracha.
Removed Area-Analyzer label.
Added Area-Language label.

@gbracha
Copy link
Contributor

gbracha commented Jan 2, 2015

The spec says that the scope of a function's signature is the function's enclosing scope, so in this case, the default value is the top level function f. It is therefore impossible for a parameters default to refer to itself, and the analogy to locals is unfounded.

I'm passing this to the analyzer team to check if they need this is still an issue or give any other feedback.


Removed Area-Language label.
Added Area-Analyzer label.

@bwilkerson
Copy link
Member

Removed Priority-Unassigned label.
Added Priority-Medium label.

@bwilkerson
Copy link
Member

Added this to the 1.10 milestone.
Removed Priority-Medium label.
Added Priority-High label.

@stereotype441
Copy link
Member

Set owner to @stereotype441.
Added Started label.

@stereotype441
Copy link
Member

This is a bug in analyzer having to do specifically with function-typed formal parameters. Note that the code snippet is analyzed correctly if you change the type of the function parameter to "dynamic":

void f([dynamic f = f]) { print("?");if (f != null) f(null); }

main() {
  f();
  print("ok");
}

Fix is out for review: https://codereview.chromium.org/978633003/

@stereotype441
Copy link
Member

Fixed in revision 44212.


Added Fixed label.

@lrhn lrhn added Type-Defect area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures labels Mar 4, 2015
@lrhn lrhn added this to the 1.10 milestone Mar 4, 2015
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

4 participants