-
-
Notifications
You must be signed in to change notification settings - Fork 648
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
Compiler assertion fires for callbacks with void return type with implicit return #1438
Comments
I guess main problem is your callback's signatures has encoder.writeMap(m, (e, k) => e.writeString(k), (e, v) => e.writeString(v)); but AS it seems has problem with case when return type of callback is You could fix this just change code above to this: encoder.writeMap(m, (e, k) => { e.writeString(k) }, (e, v) => { e.writeString(v) }); |
I get the same error but in my case adding curly braces didn't help. I'm not sure which line it is anyway, is there a way to find out?
|
@letmaik try comment this line. It defenitely shoudn't compile due to AS doesn't support closures yet with free (captured) variables. |
I tried to change the code such that the CPU class implements
Then I can do However, asc complains about duplicate identifiers:
The first is the implementation in the CPU class, the other is the declaration in the interface. Looks like AS doesn't support interfaces yet? Not using an interface doesn't throw an error. |
Yes, interfaces have very basic support for now, so better use abstract classes or usual classes |
I remember touching a related aspect a while ago. The simple test function writeMap(fn: () => void): void {
}
writeMap(() => 1); now works, but it is perfectly possible that there is more to it. @MaxGraey? |
Yes, I think we can make an exception for single-line arrow functions, but only for the "void" case. function writeMap(fn: () => void): void {
}
writeMap(() => 1); not valid: function writeMap(fn: () => void): void {
}
writeMap(() => {
return 1;
}); |
I have code that looks like:
with a
package.json
that has:and when I run
npm run asbuild
, I get a compiler assertion error that looks like:when I change the line:
to
the compiler assertion no longer fires and the code builds successfully.
I also tried
but that still causes the assertion to fire.
The issue title is my best guess at what's causing this assertion to fire since all that changed was adding curly braces around the function body.
The behaviour I would expect in this case is the compiler to either compile my code successfully or reject the code complaining that the inferred return type of the function and declared type are different.
The text was updated successfully, but these errors were encountered: