Skip to content

No error on wrong type of the default value of a redirectee constructor #53997

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

Open
sgrekhov opened this issue Nov 9, 2023 · 2 comments
Open
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). cfe-dysfunctionalities Issues for the CFE not behaving as intended

Comments

@sgrekhov
Copy link
Contributor

sgrekhov commented Nov 9, 2023

Please see Dart language specification 10.7.2 Factories

Assume that C<X1 extends B1 . . . , Xm extends Bm> is the name and
formal type parameters of the enclosing class, const? is const or empty, N
is C or C.id0 for some identifier id0, and id is an identifier, then consider a
declaration of a redirecting factory constructor k of one of the forms
const? factory
N(T1 x1 . . . , Tn xn, [Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk]) = R;
const? factory
N(T1 x1 . . . , Tn xn, {Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk}) = R;
where R is of one of the forms T<S1 . . . , Sp> or T<S1 . . . , Sp>.id. R
...
Otherwise, the redirectee constructor for this declaration is the constructor k′ denoted by R.
...
It is a compile-time error if a formal parameter of k′ has a default value
whose type is not a subtype of the type annotation on the corresponding formal
parameter in k.

But the example below has no expected error nor in analyzer nor in CFE

const num pi = 3.14 as num;

class F {
  factory F(int x, [int y]) = C;
//                            ^
// [analyzer] unspecified
// [cfe] unspecified
}

class C implements F {
  C(int x, [num y = pi]) {}
}

main() {
  F(42); // no error
}

Tested on Dart SDK version: 3.3.0-107.0.dev (dev) (Wed Nov 8 04:03:03 2023 -0800) on "windows_x64"

@lrhn
Copy link
Member

lrhn commented Nov 9, 2023

Correct. Also noticed here: dart-lang/language#3427 (comment)

It's unclear whether we want this fixed, or want to change the spec. It's been live for a while, and could be in used.

@lrhn lrhn added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). area-fe-analyzer-shared labels Nov 9, 2023
@johnniwinther johnniwinther added the cfe-dysfunctionalities Issues for the CFE not behaving as intended label Nov 9, 2023
@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-fe-analyzer-shared labels Apr 1, 2025
@johnniwinther
Copy link
Member

cc @chloestefantsova

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. area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). cfe-dysfunctionalities Issues for the CFE not behaving as intended
Projects
None yet
Development

No branches or pull requests

3 participants