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

[dart2wasm]: Unexpected type StructuralParameterType StructuralParameterType(T). #59989

Open
ykmnkmi opened this issue Jan 27, 2025 · 9 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@ykmnkmi
Copy link
Contributor

ykmnkmi commented Jan 27, 2025

Got this error and don't know which as throws:

Running dart compile wasm...
  - input file name   = file:///C:/.../web/main.dart
  - output file name  = .\web\main.wasm
  - librariesSpecPath = null
  - packagesPath file = null
  - platformPath file = file:///C:/.../Dart/lib/_internal/dart2wasm_platform.dill
  - generate source maps = true
Unhandled exception:
Unexpected type StructuralParameterType StructuralParameterType(T)
#0      TypesBuilder.fromStaticType (package:vm/transformations/type_flow/types.dart:261)
#1      SummaryCollector._typeCheck (package:vm/transformations/type_flow/summary_collector.dart:1260)
#3      AsExpression.accept (package:kernel/src/ast/expressions.dart:3628)
#4      SummaryCollector._visit (package:vm/transformations/type_flow/summary_collector.dart:975)
#5      SummaryCollector.visitExpressionStatement (package:vm/transformations/type_flow/summary_collector.dart:2300)
#6      ExpressionStatement.accept (package:kernel/src/ast/statements.dart:50)
#7      SummaryCollector._visitWithoutResult (package:vm/transformations/type_flow/summary_collector.dart:978)
#8      List.forEach (dart:core-patch/growable_array.dart:417)
#9      SummaryCollector.visitBlock (package:vm/transformations/type_flow/summary_collector.dart:2251)
#10     Block.accept (package:kernel/src/ast/statements.dart:103)
#11     SummaryCollector._visitWithoutResult (package:vm/transformations/type_flow/summary_collector.dart:978)
#12     SummaryCollector.createSummary (package:vm/transformations/type_flow/summary_collector.dart:838)
#13     TypeFlowAnalysis.getSummary (package:vm/transformations/type_flow/analysis.dart:1912)
#14     _DirectInvocation._processFunction (package:vm/transformations/type_flow/analysis.dart:399)
#15     _DirectInvocation.process (package:vm/transformations/type_flow/analysis.dart:288)
#16     _WorkList.processInvocation (package:vm/transformations/type_flow/analysis.dart:1793)
#17     _WorkList.process (package:vm/transformations/type_flow/analysis.dart:1736)
#18     TypeFlowAnalysis.process (package:vm/transformations/type_flow/analysis.dart:1941)
#19     transformComponent (package:vm/transformations/type_flow/transformer.dart:122)
#20     compileToModule (package:dart2wasm/compile.dart:221)
<asynchronous suspension>
#21     generateWasm (package:dart2wasm/generate_wasm.dart:51)
<asynchronous suspension>
#22     main (file:///C:/b/s/w/ir/x/w/sdk/pkg/dart2wasm/bin/dart2wasm.dart:10)
<asynchronous suspension>
@ykmnkmi
Copy link
Contributor Author

ykmnkmi commented Jan 27, 2025

Dart 3.6.0 (stable) (Thu Dec 5 07:46:24 2024 -0800) on "windows_x64".

@dart-github-bot
Copy link
Collaborator

Summary: dart2wasm compilation fails with Unexpected type StructuralParameterType error during type checking, likely caused by a type mismatch in the user's code. The specific location is unclear.

@dart-github-bot dart-github-bot added area-dart2wasm Issues for the dart2wasm compiler. 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 Jan 27, 2025
@ykmnkmi
Copy link
Contributor Author

ykmnkmi commented Jan 27, 2025

Compiles with dart2js and ddc.

@mraleph mraleph removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Jan 27, 2025
@mraleph
Copy link
Member

mraleph commented Jan 27, 2025

cc @alexmarkov

@ykmnkmi
Copy link
Contributor Author

ykmnkmi commented Jan 27, 2025

Same with 3.6.1.

@alexmarkov alexmarkov self-assigned this Jan 27, 2025
@alexmarkov
Copy link
Contributor

TFA crashes as it doesn't support as checks against StructuralParameterType types.

However, I'm not sure how to create an example of such as check: StructuralParameterType is a type for a StructuralParameter which represents a type parameter in a function type, and such type parameters presumably cannot be used outside of function types. @johnniwinther @chloestefantsova Could you help me to create an example of such as check?

@ykmnkmi Could you try to reduce your app to a small example which would still crash the compiler?

@alexmarkov alexmarkov removed their assignment Jan 27, 2025
@ykmnkmi
Copy link
Contributor Author

ykmnkmi commented Jan 27, 2025

@alexmarkov wokring on it.

@ykmnkmi
Copy link
Contributor Author

ykmnkmi commented Jan 28, 2025

@alexmarkov

import 'dart:js_interop';

import 'package:web/web.dart';

void main() {
  void handler<T extends Event>(Element element, T event) {
    print(element == event.currentTarget);
  }

  // throws
  // JSExportedDartFunction jsHandler = handler.toJSCaptureThis;

  // works
  JSExportedDartFunction jsHandler = handler<MouseEvent>.toJSCaptureThis;
  document.body!.addEventListener('click', jsHandler);
}

@chloestefantsova chloestefantsova self-assigned this Jan 28, 2025
@chloestefantsova chloestefantsova added area-front-end Use area-front-end for front end / CFE / kernel format related issues. and removed area-dart2wasm Issues for the dart2wasm compiler. labels Jan 28, 2025
@chloestefantsova
Copy link
Contributor

Chances are, it's a CFE issue. StructuralParameterTypes should not appear on their own, outside of the scope of a FunctionType's generic parameters.

I've updated the labels accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants