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

Dart does not throw error if function type alias type parameter bound type is not instantiated #42435

Closed
iarkh opened this issue Jun 22, 2020 · 8 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-missing-error P2 A bug or feature request we're likely to work on

Comments

@iarkh
Copy link
Contributor

iarkh commented Jun 22, 2020

Dart VM version: 2.9.0-17.0.dev (dev) (Thu Jun 18 10:22:39 2020 +0200) on "windows_x64"

The following source code example passes with dart and throws a compile error with analyzer:

class A<X extends A<X>> {}
typedef AAlias = Function<X extends A>();
main() {}

Seems like dart should throw a compile error here too.

Sample output is:

$> dart test.dart

$> dartanalyzer test.dart
Analyzing test.dart...
error - Type parameter bound types must be instantiated. - test.dart:2:37 - not_instantiated_bound
1 error found.

@keertip keertip added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Jun 22, 2020
@a-siva
Copy link
Contributor

a-siva commented Jun 22, 2020

/cc @crelier

@alexmarkov
Copy link
Contributor

/cc @leafpetersen @johnniwinther

@johnniwinther johnniwinther added area-front-end Use area-front-end for front end / CFE / kernel format related issues. and removed area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. labels Jun 23, 2020
@johnniwinther
Copy link
Member

Likely related to #41684

@leafpetersen
Copy link
Member

cc @eernstg

@eernstg
Copy link
Member

eernstg commented Jun 30, 2020

The type Function<X extends A>() is a compile-time error, because it declares a type parameter (X) with a bound (A) which is raw and doesn't have simple bounds.

So there's a missing check in the CFE for having simple bounds.

The issue arises independently of the type alias:

class A<X extends A<X>> {}
Function<X extends A>() f = throw 1;
main() {}

This program is accepted by the CFE, even though A is raw, does not have simple bounds, and is used as a type parameter bound.

@eernstg
Copy link
Member

eernstg commented Mar 23, 2021

Cf. our discussions earlier today: Reading the error specification again, it does actually apply for formal type parameters declared by any kind of entity (in particular, it applies for formal type parameters of a function declaration and of a function type). So there is no need to change the specification after all.

@eernstg
Copy link
Member

eernstg commented Mar 23, 2021

Re-checking: This issue should remain open at this point, dart still does not report the error (that the raw type A cannot be a bound, because it does not have simple bounds).

@leafpetersen leafpetersen added this to the March Beta Release milestone Mar 29, 2021
@franklinyow franklinyow added the P2 A bug or feature request we're likely to work on label Mar 29, 2021
@chloestefantsova chloestefantsova self-assigned this Mar 31, 2021
@chloestefantsova
Copy link
Contributor

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

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. front-end-missing-error P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

9 participants