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 crash: type '_ConstructorNameWithInvalidTypeArgs' is not a subtype of type 'ConstructorNameImpl?' in type cast #59592

Open
jensjoha opened this issue Nov 22, 2024 · 2 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jensjoha
Copy link
Contributor

I have this weird script, t.dart:

import "t.dart" as a;

enum MyEnum implements Bar<({a.B<int, (int c,)> e, Foo f})> {
  a;

  get field => throw "no";
}

class Bar<E> {
  final E field;
  Bar(this.field);
}

class B<E, F> {}

class Foo {}

Analyzing it is fine:

$ out/ReleaseX64/dart-sdk/bin/dart analyze t.dart
Analyzing t.dart...
No issues found!

If I then remove a comma:

import "t.dart" as a;

enum MyEnum implements Bar<({a.B<int, (int c)> e, Foo f})> {
  a;

  get field => throw "no";
}

class Bar<E> {
  final E field;
  Bar(this.field);
}

class B<E, F> {}

class Foo {}

it crashes:

$ out/ReleaseX64/dart-sdk/bin/dart analyze t.dart
Analyzing t.dart...
An unexpected error was encountered by the Analysis Server.
Please file an issue at https://github.com/dart-lang/sdk/issues/new/choose with the following details:

Internal error: type '_ConstructorNameWithInvalidTypeArgs' is not a subtype of type 'ConstructorNameImpl?' in type cast
#0      LegacyAnalysisServer.sendServerErrorNotification (package:analysis_server/src/legacy_analysis_server.dart:742:31)
#1      ErrorNotifier.logException (package:analysis_server/src/server/error_notifier.dart:45:12)
#2      MulticastInstrumentationService.logException (package:analyzer/instrumentation/multicast_service.dart:28:15)
#3      Driver._captureExceptions.errorFunction (package:analysis_server/src/server/driver.dart:557:15)
#4      _Zone._processUncaughtError (dart:async/zone.dart:1178:14)
#5      _CustomZone.handleUncaughtError (dart:async/zone.dart:1399:5)
#6      Future._propagateToListeners (dart:async/future_impl.dart:832:24)
#7      Future._completeError (dart:async/future_impl.dart:730:5)
<asynchronous suspension>

Unhandled exception:
type '_ConstructorNameWithInvalidTypeArgs' is not a subtype of type 'ConstructorNameImpl?' in type cast
#0      AstBuilder.handleEnumElement (package:analyzer/src/fasta/ast_builder.dart:4091:32)
#1      Parser.parseEnumElement (package:_fe_analyzer_shared/src/parser/parser_impl.dart:2665:14)
#2      Parser.parseEnum (package:_fe_analyzer_shared/src/parser/parser_impl.dart:2422:17)
#3      Parser.parseTopLevelKeywordDeclaration (package:_fe_analyzer_shared/src/parser/parser_impl.dart:687:14)
#4      Parser.parseTopLevelDeclarationImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:533:14)
#5      Parser.parseUnit (package:_fe_analyzer_shared/src/parser/parser_impl.dart:411:15)
#6      Parser.parseCompilationUnit2 (package:analyzer/src/generated/parser.dart:100:32)
#7      Parser.parseCompilationUnit (package:analyzer/src/generated/parser.dart:96:12)
#8      FileState.parseCode.<anonymous closure> (package:analyzer/src/dart/analysis/file_state.dart:697:25)
#9      OperationPerformanceImpl.run (package:analyzer/src/util/performance/operation_performance.dart:155:23)
#10     FileState.parseCode (package:analyzer/src/dart/analysis/file_state.dart:671:24)
#11     FileState.getParsed (package:analyzer/src/dart/analysis/file_state.dart:628:16)
#12     FileState._getUnlinkedUnit (package:analyzer/src/dart/analysis/file_state.dart:905:16)
#13     FileState.refresh.<anonymous closure> (package:analyzer/src/dart/analysis/file_state.dart:746:29)
#14     OperationPerformanceImpl.run (package:analyzer/src/util/performance/operation_performance.dart:155:23)
#15     FileState.refresh (package:analyzer/src/dart/analysis/file_state.dart:745:17)
#16     FileSystemState._newFile.<anonymous closure> (package:analyzer/src/dart/analysis/file_state.dart:1709:12)
#17     OperationPerformanceImpl.run (package:analyzer/src/util/performance/operation_performance.dart:155:23)
#18     FileSystemState._newFile (package:analyzer/src/dart/analysis/file_state.dart:1708:17)
#19     FileSystemState.getFileForPath (package:analyzer/src/dart/analysis/file_state.dart:1502:14)
#20     AnalysisDriver._discoverLibraries (package:analyzer/src/dart/analysis/driver.dart:1671:16)
#21     AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1188:5)
#22     AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2431:24)
<asynchronous suspension>
Bad state: The analysis server crashed unexpectedly
@dart-github-bot
Copy link
Collaborator

Summary: The Dart analyzer crashes when parsing a complex enum declaration. Removing a comma in the type arguments triggers a type cast error.

@dart-github-bot dart-github-bot added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Nov 22, 2024
@bwilkerson
Copy link
Member

@scheglov

@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Nov 22, 2024
@srawlins srawlins added the crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. label Nov 22, 2024
@pq pq added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Nov 22, 2024
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. crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants