You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: I am not sure whether this is considered as a bug or not since it does not result in incorrect behaviour, but it does feel like it should not happen.
This results in a successful build, even though the function call in errdefer f(); is invalid. Do note that uncommenting the try e(); line results in an error, as expected. Thus the issue seems that the compiler is not checking some semantics of the function call if it realises that the errdefer call never gets called. As stated above, this may not be considered a bug perse, but adding a try in a function only to then realise that a previous errdefer call is invalid seems wrong.
NOTE: This happens on 0.13.0 aswell, I was not sure whether the above field can take a list of versions
Expected Behavior
The compiler should output an error even if the errdefer is never called.
In terms of use case I encountered this because I was writing a resource acquisition function, I preemptively added an errdefer in case I later append more code to it, I then added another try statement later on and the call failed.
fn init(self: *S) !void {
self.r = try acquire(1);
errdefer release(self.r); // missed 1 as first parameter - see deinit()
// later added another call and compilation failed
try somethingelse();
}
fn deinit(self: *S) {
release(1, self.r);
}
The text was updated successfully, but these errors were encountered:
Zig Version
0.14.0
Steps to Reproduce and Observed Behavior
Note: I am not sure whether this is considered as a bug or not since it does not result in incorrect behaviour, but it does feel like it should not happen.
Run the following bash script:
This results in a successful build, even though the function call in
errdefer f();
is invalid. Do note that uncommenting thetry e();
line results in an error, as expected. Thus the issue seems that the compiler is not checking some semantics of the function call if it realises that theerrdefer
call never gets called. As stated above, this may not be considered a bug perse, but adding a try in a function only to then realise that a previouserrdefer
call is invalid seems wrong.NOTE: This happens on
0.13.0
aswell, I was not sure whether the above field can take a list of versionsExpected Behavior
The compiler should output an error even if the
errdefer
is never called.In terms of use case I encountered this because I was writing a resource acquisition function, I preemptively added an
errdefer
in case I later append more code to it, I then added anothertry
statement later on and the call failed.The text was updated successfully, but these errors were encountered: