Skip to content

[Dart-Analysis] Internal error: type 'LibraryElementImpl' is not a subtype of type 'Fragment' in type cast #60168

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

Closed
NiclasLeichsenring opened this issue Feb 19, 2025 · 6 comments
Assignees
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. P2 A bug or feature request we're likely to work on

Comments

@NiclasLeichsenring
Copy link

The Dart Analysis Server crashes while I am analyzing my project since I updated to Flutter 3.29:

Dart SDK version: 3.7.0 (stable) (Wed Feb 5 04:53:58 2025 -0800) on "macos_arm64"

Dart analysis issue

Internal error: type 'LibraryElementImpl' is not a subtype of type 'Fragment' in type cast

Version information

  • Dart SDK 3.7.0
  • Dart IntelliJ 242.24931
  • Android Studio Ladybug Feature Drop | 2024.2.2 Patch 1
  • Mac OS X 15.3

Details

Internal error: type 'LibraryElementImpl' is not a subtype of type 'Fragment' in type cast
#0 LocalVariableElementImpl.enclosingFragment (package:analyzer/src/dart/element/element.dart:7487:55)
#1 _VariableBinder.joinPatternVariables (package:analyzer/src/dart/resolver/resolution_visitor.dart:1976:35)
#2 VariableBinder.logicalOrPatternFinish (package:_fe_analyzer_shared/src/type_inference/variable_bindings.dart:109:11)
#3 ResolutionVisitor.visitLogicalOrPattern (package:analyzer/src/dart/resolver/resolution_visitor.dart:1037:23)
#4 LogicalOrPatternImpl.accept (package:analyzer/src/dart/ast/ast.dart:11472:50)
#5 ResolutionVisitor.visitLogicalOrPattern (package:analyzer/src/dart/resolver/resolution_visitor.dart:1034:22)
#6 LogicalOrPatternImpl.accept (package:analyzer/src/dart/ast/ast.dart:11472:50)
#7 ResolutionVisitor._resolveGuardedPattern (package:analyzer/src/dart/resolver/resolution_visitor.dart:1615:28)
#8 ResolutionVisitor.visitSwitchExpression. (package:analyzer/src/dart/resolver/resolution_visitor.dart:1324:9)
#9 ResolutionVisitor._withNameScope (package:analyzer/src/dart/resolver/resolution_visitor.dart:1899:8)
#10 ResolutionVisitor.visitSwitchExpression (package:analyzer/src/dart/resolver/resolution_visitor.dart:1323:7)
#11 SwitchExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:17115:50)
#12 AstResolver.resolveExpression (package:analyzer/src/summary2/ast_resolver.dart:107:10)
#13 _PropertyInducingElementTypeInference.perform (package:analyzer/src/summary2/top_level_inference.dart:265:17)
#14 PropertyInducingElementImpl.type (package:analyzer/src/dart/element/element.dart:10031:28)
#15 _InitializerInference.perform (package:analyzer/src/summary2/top_level_inference.dart:155:15)
#16 TopLevelInference.infer (package:analyzer/src/summary2/top_level_inference.dart:108:26)
#17 Linker._performTopLevelInference (package:analyzer/src/summary2/link.dart:426:29)
#18 Linker._buildOutlines (package:analyzer/src/summary2/link.dart:270:5)

#19 Linker.link. (package:analyzer/src/summary2/link.dart:125:7)

#20 OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)

#21 Linker.link (package:analyzer/src/summary2/link.dart:124:5)

#22 link (package:analyzer/src/summary2/link.dart:43:3)

#23 LibraryContext.load.loadBundle. (package:analyzer/src/dart/analysis/library_context.dart:201:22)

#24 OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)

#25 LibraryContext.load.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:198:24)

#26 LibraryContext.load. (package:analyzer/src/dart/analysis/library_context.dart:286:7)

#27 PerformanceLog.runAsync (package:analyzer/src/dart/analysis/performance_logger.dart:50:14)

#28 LibraryContext.load (package:analyzer/src/dart/analysis/library_context.dart:277:5)

#29 AnalysisDriver._produceErrors (package:analyzer/src/dart/analysis/driver.dart:1933:5)

#30 AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1265:7)

#31 AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2438:7)

#0 LibraryContext._throwLibraryCycleLinkException (package:analyzer/src/dart/analysis/library_context.dart:415:5)
#1 LibraryContext.load.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:212:11)

#2 LibraryContext.load. (package:analyzer/src/dart/analysis/library_context.dart:286:7)

#3 PerformanceLog.runAsync (package:analyzer/src/dart/analysis/performance_logger.dart:50:14)

#4 LibraryContext.load (package:analyzer/src/dart/analysis/library_context.dart:277:5)

#5 AnalysisDriver._produceErrors (package:analyzer/src/dart/analysis/driver.dart:1933:5)

#6 AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1265:7)

#7 AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2438:7)

@NiclasLeichsenring NiclasLeichsenring added the legacy-area-analyzer Use area-devexp instead. label Feb 19, 2025
@johnniwinther johnniwinther added area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 19, 2025
@scheglov
Copy link
Contributor

Do you have code that can reproduce this issue?

@scheglov
Copy link
Contributor

Ah, looking closer into the stack trace, I saw nested LogicalOrPatterns.
It does not reproduce with two of them.
But does reproduce with three.

var x = switch (0) {
  var a || var a || var a => 0;
}

@scheglov
Copy link
Contributor

@scheglov scheglov added the P2 A bug or feature request we're likely to work on label Feb 20, 2025
copybara-service bot pushed a commit that referenced this issue Feb 20, 2025
… when merging LogicalOrPattern.

Bug: #60168
Change-Id: Id77cd5975c6a090237eb011bb4eca91e18fedf2b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410840
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
@NiclasLeichsenring
Copy link
Author

NiclasLeichsenring commented Mar 14, 2025

Hi @scheglov @johnniwinther , this issue has not been fixed with Flutter 3.29.2 and Dart 3.7.2

Dart analysis issue

Internal error: type 'LibraryElementImpl' is not a subtype of type 'Fragment' in type cast

Version information

  • Dart SDK 3.7.2
  • Dart IntelliJ 243.23177
  • Android Studio Meerkat | 2024.3.1
  • Mac OS X 15.3

Details

Internal error: type 'LibraryElementImpl' is not a subtype of type 'Fragment' in type cast
#0 LocalVariableElementImpl.enclosingFragment (package:analyzer/src/dart/element/element.dart:7487:55)
#1 _VariableBinder.joinPatternVariables (package:analyzer/src/dart/resolver/resolution_visitor.dart:1976:35)
#2 VariableBinder.logicalOrPatternFinish (package:_fe_analyzer_shared/src/type_inference/variable_bindings.dart:109:11)
#3 ResolutionVisitor.visitLogicalOrPattern (package:analyzer/src/dart/resolver/resolution_visitor.dart:1037:23)
#4 LogicalOrPatternImpl.accept (package:analyzer/src/dart/ast/ast.dart:11472:50)
#5 ResolutionVisitor.visitLogicalOrPattern (package:analyzer/src/dart/resolver/resolution_visitor.dart:1034:22)
#6 LogicalOrPatternImpl.accept (package:analyzer/src/dart/ast/ast.dart:11472:50)
#7 ResolutionVisitor._resolveGuardedPattern (package:analyzer/src/dart/resolver/resolution_visitor.dart:1615:28)
#8 ResolutionVisitor.visitSwitchExpression. (package:analyzer/src/dart/resolver/resolution_visitor.dart:1324:9)
#9 ResolutionVisitor._withNameScope (package:analyzer/src/dart/resolver/resolution_visitor.dart:1899:8)
#10 ResolutionVisitor.visitSwitchExpression (package:analyzer/src/dart/resolver/resolution_visitor.dart:1323:7)
#11 SwitchExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:17115:50)
#12 AstResolver.resolveExpression (package:analyzer/src/summary2/ast_resolver.dart:107:10)
#13 _PropertyInducingElementTypeInference.perform (package:analyzer/src/summary2/top_level_inference.dart:265:17)
#14 PropertyInducingElementImpl.type (package:analyzer/src/dart/element/element.dart:10031:28)
#15 _InitializerInference.perform (package:analyzer/src/summary2/top_level_inference.dart:155:15)
#16 TopLevelInference.infer (package:analyzer/src/summary2/top_level_inference.dart:108:26)
#17 Linker._performTopLevelInference (package:analyzer/src/summary2/link.dart:426:29)
#18 Linker._buildOutlines (package:analyzer/src/summary2/link.dart:270:5)

#19 Linker.link. (package:analyzer/src/summary2/link.dart:125:7)

#20 OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)

#21 Linker.link (package:analyzer/src/summary2/link.dart:124:5)

#22 link (package:analyzer/src/summary2/link.dart:43:3)

#23 LibraryContext.load.loadBundle. (package:analyzer/src/dart/analysis/library_context.dart:201:22)

#24 OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)

#25 LibraryContext.load.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:198:24)

#26 LibraryContext.load.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:148:9)

#27 LibraryContext.load. (package:analyzer/src/dart/analysis/library_context.dart:286:7)

#28 PerformanceLog.runAsync (package:analyzer/src/dart/analysis/performance_logger.dart:50:14)

#29 LibraryContext.load (package:analyzer/src/dart/analysis/library_context.dart:277:5)

#30 AnalysisDriver._produceErrors (package:analyzer/src/dart/analysis/driver.dart:1933:5)

#31 AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1265:7)

#32 AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2438:7)

#0      LibraryContext._throwLibraryCycleLinkException (package:analyzer/src/dart/analysis/library_context.dart:415:5)
#1      LibraryContext.load.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:212:11)
<asynchronous suspension>
#2      LibraryContext.load.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:148:9)
<asynchronous suspension>
#3      LibraryContext.load.<anonymous closure> (package:analyzer/src/dart/analysis/library_context.dart:286:7)
<asynchronous suspension>
#4      PerformanceLog.runAsync (package:analyzer/src/dart/analysis/performance_logger.dart:50:14)
<asynchronous suspension>
#5      LibraryContext.load (package:analyzer/src/dart/analysis/library_context.dart:277:5)
<asynchronous suspension>
#6      AnalysisDriver._produceErrors (package:analyzer/src/dart/analysis/driver.dart:1933:5)
<asynchronous suspension>
#7      AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1265:7)
<asynchronous suspension>
#8      AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2438:7)
<asynchronous suspension>

@johnniwinther
Copy link
Member

The fix has landed but will unfortunately not be available before Dart 3.8. It is available in the dev builds and will be part of the first 3.8 beta release.

@NiclasLeichsenring
Copy link
Author

The fix has landed but will unfortunately not be available before Dart 3.8. It is available in the dev builds and will be part of the first 3.8 beta release.

ok thank you for the info. I thought it will land in 3.7.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

3 participants