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

better error/warning message if typedef is defined inside class #3001

Closed
gramster opened this issue May 10, 2012 · 17 comments
Closed

better error/warning message if typedef is defined inside class #3001

gramster opened this issue May 10, 2012 · 17 comments
Assignees
Labels
analyzer-recovery area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-enhancement A request for a change that isn't a bug

Comments

@gramster
Copy link
Contributor

I have a class Reporter, that has a couple of members that are references to callback functions. If I declare these with 'var' things are fine. If I try to use typedefs for the signatures and strongly type the members compilation breaks in weird ways.

For example, if instead of:

var _urlFormatter;

I use:

  typedef String _UrlFormatter(String baseUrl,
                               Map marks, Map starts, Map measures);
  _UrlFormatter _urlFormatter;

I get numerous compiler errors on other lines, not on these lines. These compiler errors are, for declarations, "Duplicate top-level declaration of <foo>", and then, when foo is references, "Cannot resolve <foo>"

This is in the DartEditor on Goobuntu. Build 7243.

@sethladd
Copy link
Contributor

Hi Gram, Can you post the entire script here? Thanks!

@iposva-google
Copy link
Contributor

Added Area-Editor, Triaged labels.

@gramster
Copy link
Contributor Author

I think I found the issue. If I move the typedef to the top level things are okay, but if I put it inside a class things go awry. So this is my error, as typedef is not allowed within a class it seems. However, the error messages were very unhelpful and perhaps should be improved.

@sethladd
Copy link
Contributor

Moving to Analyzer.


Removed Area-Editor label.
Added Area-Analyzer label.

@sethladd
Copy link
Contributor

Changed the title to: "better error/warning message if typedef is defined inside class".

@bwilkerson
Copy link
Member

Added this to the Later milestone.

@bwilkerson
Copy link
Member

Removed this from the Later milestone.
Added this to the M3 milestone.

@scheglov
Copy link
Contributor

Removed this from the M3 milestone.
Added this to the Later milestone.
Added AnalysisEngine label.

@DartBot
Copy link

DartBot commented Apr 7, 2013

This comment was originally written by amouravski@google.com


Added Editor-AnalysisEngine label.

@bwilkerson
Copy link
Member

This is still a problem in analysis engine but will be addressed as part of recovery.


Set owner to @bwilkerson.
Removed AnalysisEngine, Editor-AnalysisEngine labels.

@bwilkerson
Copy link
Member

Added Analyzer-Recovery label.

@bwilkerson
Copy link
Member

Removed Type-Defect label.
Added Type-Enhancement label.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@srawlins
Copy link
Member

Some concreteness:

$ cat issue-3001.dart

class Foo {
  typedef String _UrlFormatter(String baseUrl, Map marks, Map starts, Map measures);
  _UrlFormatter _urlFormatter;
}

$ dartanalyzer issue-3001.dart
Analyzing [issue-3001.dart]...
[error] The built-in identifier 'typedef' cannot be as a type (/Users/srawlins/code/dart/dart/issue-3001.dart, line 2, col 3)
[error] Expected to find ';' (/Users/srawlins/code/dart/dart/issue-3001.dart, line 2, col 11)
[warning] '_UrlFormatter' must have a method body because 'Foo' is not abstract (/Users/srawlins/code/dart/dart/issue-3001.dart, line 2, col 18)
[warning] String is not a type (/Users/srawlins/code/dart/dart/issue-3001.dart, line 2, col 32)
[warning] _UrlFormatter is not a type (/Users/srawlins/code/dart/dart/issue-3001.dart, line 3, col 3)
2 errors and 3 warnings found.

This is with dart 1.7.0-edge.40134. I think the desired behavior is 1 error along the lines of:
[error] typedef is illegal inside a class definition (/Users/srawlins/code/dart/dart/issue-3001.dart, line 2, col 3)

@bwilkerson
Copy link
Member

Added Started label.

@bwilkerson
Copy link
Member

https://codereview.chromium.org/780403002/ (bleeding edge revision 42154)

This change causes us to produce one reasonable error (like the one suggested) for the function type alias itself but doesn't cause the name of the function type to be available in scope, so the field is still marked with a warning.


Added Fixed label.

@gramster gramster added Priority-Medium area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-recovery labels Dec 6, 2014
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-recovery area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

9 participants