Skip to content

CFE/analyzer disagreement on set literal type inference #62659

@Pante

Description

@Pante

Dart version: 3.11.0
Platform: macOS

The following code snippet that was previously working in Dart 3.10.8 does not compile on Dart 3.11.0.

class Parent {}

class Base implements Parent {}

extension type const MidA._(Parent _) implements Parent {}

extension type const A._(Base _) implements MidA, Base {}

extension type const MidB._(Parent _) implements Parent {}

extension type const B._(Base _) implements MidB, Base {}

void f(Set<Base> s) {}

void main() {
  final Set<A> a = {};
  final Set<B> b = {};

  // OK
  f({...a, ...b});

  // Error: CFE infers Set<Object> while analyzer infers Set<Base>
  final merged = {...a, ...b};
  f(merged);
}

Analyzer infers the correct type:
Image

Error:

lib/src/theme/main.dart:24:5: Error: The argument type 'Set<Object>' can't be assigned to the parameter type 'Set<Base>'.
 - 'Set' is from 'dart:core'.
 - 'Object' is from 'dart:core'.
 - 'Base' is from 'package:forui/src/theme/main.dart' ('lib/src/theme/main.dart').
  f(merged);
    ^

Process finished with exit code 254

Metadata

Metadata

Labels

area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-discrepancyDiscrepancies between analyzer and cfetype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions