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

isAssignableFromType throws null check error for Function types #619

Open
leonsenft opened this issue Sep 9, 2022 · 5 comments
Open

isAssignableFromType throws null check error for Function types #619

leonsenft opened this issue Sep 9, 2022 · 5 comments

Comments

@leonsenft
Copy link

The implementation null asserts DartType.element2:

bool isAssignableFromType(DartType staticType) =>
isAssignableFrom(staticType.element2!);

Which is always null for Function types:
https://github.com/dart-lang/sdk/blob/d6ff1193c5eb1d4b98e232f545cce49c63492b5c/pkg/analyzer/lib/src/dart/element/type.dart#L95-L96

@leonsenft
Copy link
Author

@grouma this has been the cause of several unique unhandled exceptions in the Angular compiler.

@grouma
Copy link
Member

grouma commented Sep 9, 2022

cc @natebosch

@natebosch
Copy link
Member

Making an implementation that works for structural types is not trivial.

I think that these types also don't work in the angular compiler though - you can't inject a Function type right? Is there some safeguard you can move earlier in the compilation to prevent this?

@leonsenft
Copy link
Author

I understand that, but perhaps it would make sense to throw an explicit error instead of knowingly failing a null check.

For now, I'm creating an extension method to wrap this method and throw such an error if the underlying type is a FunctionType.

@natebosch
Copy link
Member

Yeah, I think we can throw some more informative errors, and perhaps even more eagerly in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants