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 ignores all errors if a field parameter with type parameters is present in a constructor #46968

Closed
Quijx opened this issue Aug 23, 2021 · 2 comments
Assignees
Labels
analyzer-crash-report Issues which have been reported due to an analysis server crash area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on

Comments

@Quijx
Copy link

Quijx commented Aug 23, 2021

Running dart analyze on the following code should show various errors:

void main() {
  print(x); // x is accessed before it is defined
  final x = 5;

  bar(); // bar does not exist
  
  return 0; // cant return int in void function
}
} // one bracket too much

class Foo {
  Foo(this.f<String>()); // type parameter on field parameter

  void Function<T>() f;
} 

However the analyzer reports No issues found!. For example dart run does find these errors though. If the constructor is removed, the errors are reported correctly by the analyzer.

Output of dart --version: Dart SDK version: 2.14.0-301.0.dev (dev) (Sat Jul 10 17:56:59 2021 -0700) on "linux_x64"

@lrhn lrhn added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Aug 24, 2021
@scheglov
Copy link
Contributor

I believe what happens here is that this code crashes the analyzer, so it fails to report any diagnostics.

  RangeError (index): Invalid value: Valid value range is empty: 0
  #0      List.[] (dart:core-patch/array.dart:268:52)
  #1      ElementWalker.getTypeParameter (package:analyzer/src/generated/declaration_resolver.dart:202:23)
  #2      ResolutionVisitor._buildTypeParameterElements (package:analyzer/src/dart/resolver/resolution_visitor.dart:1124:35)
  #3      ResolutionVisitor.visitFieldFormalParameter.<anonymous closure>.<anonymous closure> (package:analyzer/src/dart/resolver/resolution_visitor.dart:479:9)
  #4      ResolutionVisitor._withNameScope (package:analyzer/src/dart/resolver/resolution_visitor.dart:1324:8)
  #5      ResolutionVisitor.visitFieldFormalParameter.<anonymous closure> (package:analyzer/src/dart/resolver/resolution_visitor.dart:478:7)
  #6      ResolutionVisitor._withElementHolder (package:analyzer/src/dart/resolver/resolution_visitor.dart:1302:8)
  #7      ResolutionVisitor.visitFieldFormalParameter (package:analyzer/src/dart/resolver/resolution_visitor.dart:477:5)
  #8      FieldFormalParameterImpl.accept (package:analyzer/src/dart/ast/ast.dart:4067:15)
  #9      NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7483:20)
  #10     FormalParameterListImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:4423:17)
  #11     RecursiveAstVisitor.visitFormalParameterList (package:analyzer/dart/ast/visitor.dart:917:10)
  #12     FormalParameterListImpl.accept (package:analyzer/src/dart/ast/ast.dart:4419:50)
  #13     ResolutionVisitor.visitConstructorDeclaration.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:analyzer/src/dart/resolver/resolution_visitor.dart:298:31)
  #14     ResolutionVisitor._withElementWalker (package:analyzer/src/dart/resolver/resolution_visitor.dart:1313:8)
  #15     ResolutionVisitor.visitConstructorDeclaration.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:analyzer/src/dart/resolver/resolution_visitor.dart:295:11)
  #16     ResolutionVisitor._withNameScope (package:analyzer/src/dart/resolver/resolution_visitor.dart:1324:8)
  #17     ResolutionVisitor.visitConstructorDeclaration.<anonymous closure>.<anonymous closure> (package:analyzer/src/dart/resolver/resolution_visitor.dart:292:9)
  #18     ResolutionVisitor._withElementWalker (package:analyzer/src/dart/resolver/resolution_visitor.dart:1313:8)
  #19     ResolutionVisitor.visitConstructorDeclaration.<anonymous closure> (package:analyzer/src/dart/resolver/resolution_visitor.dart:291:7)
  #20     ResolutionVisitor._withElementHolder (package:analyzer/src/dart/resolver/resolution_visitor.dart:1302:8)
  #21     ResolutionVisitor.visitConstructorDeclaration (package:analyzer/src/dart/resolver/resolution_visitor.dart:290:5)
  #22     ConstructorDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:2475:15)
  #23     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7483:20)
  #24     ResolutionVisitor.visitClassDeclaration.<anonymous closure>.<anonymous closure> (package:analyzer/src/dart/resolver/resolution_visitor.dart:246:22)
  #25     ResolutionVisitor._withNameScope (package:analyzer/src/dart/resolver/resolution_visitor.dart:1324:8)
  #26     ResolutionVisitor.visitClassDeclaration.<anonymous closure> (package:analyzer/src/dart/resolver/resolution_visitor.dart:227:7)
  #27     ResolutionVisitor._withElementWalker (package:analyzer/src/dart/resolver/resolution_visitor.dart:1313:8)
  #28     ResolutionVisitor.visitClassDeclaration (package:analyzer/src/dart/resolver/resolution_visitor.dart:226:5)
  #29     ClassDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:1479:50)
  #30     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7483:20)
  #31     CompilationUnitImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2068:21)
  #32     RecursiveAstVisitor.visitCompilationUnit (package:analyzer/dart/ast/visitor.dart:749:10)
  #33     CompilationUnitImpl.accept (package:analyzer/src/dart/ast/ast.dart:2061:50)
  #34     LibraryAnalyzer._resolveFile (package:analyzer/src/dart/analysis/library_analyzer.dart:669:10)

@scheglov scheglov added analyzer-crash-report Issues which have been reported due to an analysis server crash P2 A bug or feature request we're likely to work on labels Aug 26, 2021
@scheglov scheglov self-assigned this Aug 26, 2021
@scheglov
Copy link
Contributor

#46968

dart-bot pushed a commit that referenced this issue Aug 26, 2021
…ter has type parameters.

Bug: #46968
Change-Id: I20ba948b26040e00635612f52af7cf7e51230695
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211465
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-crash-report Issues which have been reported due to an analysis server crash area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

3 participants