Skip to content

CFE crashes on a conditional expression involving a record #49914

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
alexmarkov opened this issue Sep 7, 2022 · 1 comment
Closed

CFE crashes on a conditional expression involving a record #49914

alexmarkov opened this issue Sep 7, 2022 · 1 comment
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@alexmarkov
Copy link
Contributor

Part of #49713.

Consider the following example:

void main(List<String> args) {
  (int, int) x = (1, 2);
  (int, int) y = (3, 4);
  (int, int) z = args.length > 0 ? x : y;
  print(z);
}

CFE crashes in the following way:

Crash when compiling file://.../foo.dart,
at character offset 88:
type 'RecordType' is not a subtype of type 'InterfaceType' in type cast
#0      StandardBounds.getNullabilityAwareStandardUpperBoundInternal (package:kernel/src/standard_bounds.dart:830:13)
#1      TypeSchemaStandardBounds.getNullabilityAwareStandardUpperBoundInternal (package:front_end/src/fasta/type_inference/standard_bounds.dart:57:18)
#2      StandardBounds._getNullabilityAwareStandardUpperBound (package:kernel/src/standard_bounds.dart:625:12)
#3      StandardBounds.getStandardUpperBound (package:kernel/src/standard_bounds.dart:613:14)
#4      InferenceVisitorImpl.visitConditionalExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:860:51)
#5      ConditionalExpression.accept1 (package:kernel/ast.dart:7142:9)
#6      InferenceVisitorImpl._inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:136:27)
#7      InferenceVisitorImpl.inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:171:40)
#8      InferenceVisitorImpl.visitVariableDeclaration (package:front_end/src/fasta/type_inference/inference_visitor.dart:6828:27)
#9      VariableDeclaration.accept (package:kernel/ast.dart:11006:43)
#10     InferenceVisitorImpl.inferStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:107:26)
#11     InferenceVisitorImpl._visitStatements (package:front_end/src/fasta/type_inference/inference_visitor.dart:720:50)
#12     InferenceVisitorImpl.visitBlock (package:front_end/src/fasta/type_inference/inference_visitor.dart:741:31)
#13     Block.accept (package:kernel/ast.dart:9436:43)
#14     InferenceVisitorImpl.inferStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:107:26)
#15     TypeInferrerImpl.inferFunctionBody (package:front_end/src/fasta/type_inference/type_inferrer.dart:185:17)
#16     BodyBuilder.finishFunction (package:front_end/src/fasta/kernel/body_builder.dart:1327:43)
#17     DietListener.buildFunctionBody (package:front_end/src/fasta/source/diet_listener.dart:1103:19)
#18     DietListener.endTopLevelMethod (package:front_end/src/fasta/source/diet_listener.dart:376:5)
#19     Parser.parseTopLevelMethod (package:_fe_analyzer_shared/src/parser/parser_impl.dart:3480:14)
#20     Parser.parseTopLevelMemberImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:3220:14)
#21     Parser.parseTopLevelDeclarationImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:531:14)
#22     Parser.parseUnit (package:_fe_analyzer_shared/src/parser/parser_impl.dart:377:15)
#23     SourceLoader.buildBody (package:front_end/src/fasta/source/source_loader.dart:1166:12)
<asynchronous suspension>
#24     SourceLoader.buildBodies (package:front_end/src/fasta/source/source_loader.dart:663:7)
<asynchronous suspension>
#25     KernelTarget.buildComponent.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:620:7)
<asynchronous suspension>
#26     withCrashReporting (package:front_end/src/fasta/crash.dart:122:12)
<asynchronous suspension>
#27     _buildInternal (package:front_end/src/kernel_generator_impl.dart:202:19)
<asynchronous suspension>
#28     withCrashReporting (package:front_end/src/fasta/crash.dart:122:12)
<asynchronous suspension>
#29     generateKernel.<anonymous closure> (package:front_end/src/kernel_generator_impl.dart:47:12)
<asynchronous suspension>
#30     generateKernel (package:front_end/src/kernel_generator_impl.dart:46:10)
<asynchronous suspension>
#31     kernelForModule (package:front_end/src/api_prototype/kernel_generator.dart:100:11)
<asynchronous suspension>
#32     SingleShotCompilerWrapper.compileInternal (file://.../pkg/vm/bin/kernel_service.dart:412:11)
<asynchronous suspension>
#33     Compiler.compile.<anonymous closure> (file://.../pkg/vm/bin/kernel_service.dart:221:45)
<asynchronous suspension>
#34     _processLoadRequest (file://.../pkg/vm/bin/kernel_service.dart:914:37)
<asynchronous suspension>


#0      DietListener.buildFunctionBody (package:front_end/src/fasta/source/diet_listener.dart:1107:7)
#1      DietListener.endTopLevelMethod (package:front_end/src/fasta/source/diet_listener.dart:376:5)
#2      Parser.parseTopLevelMethod (package:_fe_analyzer_shared/src/parser/parser_impl.dart:3480:14)
#3      Parser.parseTopLevelMemberImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:3220:14)
#4      Parser.parseTopLevelDeclarationImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:531:14)
#5      Parser.parseUnit (package:_fe_analyzer_shared/src/parser/parser_impl.dart:377:15)
#6      SourceLoader.buildBody (package:front_end/src/fasta/source/source_loader.dart:1166:12)
<asynchronous suspension>
#7      SourceLoader.buildBodies (package:front_end/src/fasta/source/source_loader.dart:663:7)
<asynchronous suspension>
#8      KernelTarget.buildComponent.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:620:7)
<asynchronous suspension>
#9      withCrashReporting (package:front_end/src/fasta/crash.dart:122:12)
<asynchronous suspension>
#10     _buildInternal (package:front_end/src/kernel_generator_impl.dart:202:19)
<asynchronous suspension>
#11     withCrashReporting (package:front_end/src/fasta/crash.dart:122:12)
<asynchronous suspension>
#12     generateKernel.<anonymous closure> (package:front_end/src/kernel_generator_impl.dart:47:12)
<asynchronous suspension>
#13     generateKernel (package:front_end/src/kernel_generator_impl.dart:46:10)
<asynchronous suspension>
#14     kernelForModule (package:front_end/src/api_prototype/kernel_generator.dart:100:11)
<asynchronous suspension>
#15     SingleShotCompilerWrapper.compileInternal (file://.../pkg/vm/bin/kernel_service.dart:412:11)
<asynchronous suspension>
#16     Compiler.compile.<anonymous closure> (file://.../pkg/vm/bin/kernel_service.dart:221:45)
<asynchronous suspension>
#17     _processLoadRequest (file://.../pkg/vm/bin/kernel_service.dart:914:37)
<asynchronous suspension>

While type inference is not implemented for records yet, is it possible to add a trivial inference for conditional expressions in case both variants have the same type, so that we could still write conditional expressions involving records?

/cc @johnniwinther @chloestefantsova

@alexmarkov alexmarkov added the legacy-area-front-end Legacy: Use area-dart-model instead. label Sep 7, 2022
@chloestefantsova chloestefantsova self-assigned this Sep 8, 2022
@chloestefantsova
Copy link
Contributor

Thanks for reporting that. I'm working on a fix at https://dart-review.googlesource.com/c/sdk/+/258005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

2 participants