-
Notifications
You must be signed in to change notification settings - Fork 62
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
cannot assign INVALID_FUNCTION to a non-function type #338
Comments
Bug: issue #338 Test: tests/compile-only/fail-redefine-typedef.sp
This is not supported, unfortunately - types must be declared before they are used. This was inconsistent before, and this particular case only worked coincidentally. It's easy to show an example that wouldn't work on 1.9. The code below won't compile because "Bar" is a placeholder type at the point we typecheck the call to "Foo":
Pawn uses a two-pass compiler, and type information is thrown away in between passes. Your example worked because in 1.9, the placeholder for "Bar" retained the fact that it was a function, but did not retain the function's prototype. So relying on the prototype before the definition would fail. In 1.10, placeholders do not retain any information across reparses, so both examples fail. Now, I bet you're thinking: "what is this garbage and why doesn't it just work?" I agree. I think we should support types declared in any order. But we're not there yet, and I'd rather it work 100% of the time instead of 27% of the time. There is a real bug here though - "typeset Bar" should be illegal since it was already declared as a typedef. |
Well, it's been a while, thanks for your answer. Of course both declaration should be illegal. I guess the main issue was this is accepted native void Foo(Bar callback); but not this native void Foo(Bar callback = INVALID_FUNCTION); in case of "Bar" is declared afterward. |
Right - the difference is that the compiler is trying to do typechecks in the second version but not the first version. Hopefully it's more clear now. I'd like to improve this, but it's pretty difficult in the current design. |
Environment
Description
This doesn't compile en SM 1.10, but works on SM 1.9. I could not find any documentation about this. It should be declared before the native declaration, it wasn't the case before. Is this intended ?
Problematic Code
Working Code
The text was updated successfully, but these errors were encountered: