@@ -601,23 +601,28 @@ class _WasmTransformer extends Transformer {
601
601
callAsyncMap, Name ('where' ), Arguments ([whereFilter]),
602
602
interfaceTarget: whereProc, functionType: whereProcType);
603
603
604
- // Finally call cast
605
- DartType typeArgument;
606
- if (functionNode.returnType is InterfaceType ) {
607
- typeArgument =
608
- (functionNode.returnType as InterfaceType ).typeArguments.single;
604
+ // Finally call cast.
605
+
606
+ // Stream element type is defined in language spec section 9. If the return
607
+ // type is `Stream<U>` then the element type is `U`. Otherwise it needs to
608
+ // be a supertype of `Object` and the element type is `dynamic`.
609
+ final DartType streamTypeArgument;
610
+ final DartType functionReturnType = functionNode.returnType;
611
+ if (functionReturnType is InterfaceType &&
612
+ functionReturnType.classNode == coreTypes.streamClass) {
613
+ streamTypeArgument = functionReturnType.typeArguments.single;
609
614
} else {
610
- typeArgument = const DynamicType ();
615
+ streamTypeArgument = const DynamicType ();
611
616
}
612
617
Procedure castProc =
613
618
coreTypes.index.getProcedure ('dart:async' , 'Stream' , 'cast' );
614
- final returnStreamType = InterfaceType (
615
- coreTypes.streamClass, typeArgument. nullability, [typeArgument ]);
619
+ final returnStreamType = InterfaceType (coreTypes.streamClass,
620
+ streamTypeArgument. nullability, [streamTypeArgument ]);
616
621
final castProcType = FunctionType (
617
622
[], returnStreamType, Nullability .nonNullable,
618
623
requiredParameterCount: 1 );
619
624
final castToExpectedType = InstanceInvocation (InstanceAccessKind .Instance ,
620
- callWhere, Name ('cast' ), Arguments ([], types: [typeArgument ]),
625
+ callWhere, Name ('cast' ), Arguments ([], types: [streamTypeArgument ]),
621
626
interfaceTarget: castProc, functionType: castProcType);
622
627
return FunctionNode (
623
628
Block ([
0 commit comments