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
Peer type resolution is useful and convenient, but currently it takes precedence over other forms of type resolution when it shouldn't. Peer type resolution should only occur when the result type (see #2602) is unspecified. For function returns, the result type is always known because return types are a mandatory part of the function.
Here are two examples which currently fail due to this eager resolution, but which should succeed given implicit casting rules. The error is error: incompatible types: '[]u8' and '[1]u8'.
In this example, the compiler should attempt to cast each prong expression to []const u8 because the result type is predetermined by the function's return type. No peer type resolution should occur.
test"peer type resolution blocks implicit cast to return type" {
for ("hello") |c|_=f(c);
}
fnf(c: u8) []constu8 {
returnswitch (c) {
'h', 'e'=> [_]u8{c}, // should cast to slice'l', ' '=> [_]u8{ c, '.' }, // should cast to sliceelse=> ([_]u8{c})[0..], // is a slice
};
}
In this example, the compiler should attempt to cast each prong expression to []const u8 because the result type is predetermined by the explicit variable type. No peer type resolution should occur.
test"peer type resolution blocks implicit cast to variable type" {
varx: []constu8=undefined;
for ("hello") |c|x=switch (c) {
'h', 'e'=> [_]u8{c}, // should cast to slice'l', ' '=> [_]u8{ c, '.' }, // should cast to sliceelse=> ([_]u8{c})[0..], // is a slice
};
}
The text was updated successfully, but these errors were encountered:
andrewrk
added
accepted
This proposal is planned.
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
labels
Jun 25, 2019
Peer type resolution is useful and convenient, but currently it takes precedence over other forms of type resolution when it shouldn't. Peer type resolution should only occur when the result type (see #2602) is unspecified. For function returns, the result type is always known because return types are a mandatory part of the function.
Here are two examples which currently fail due to this eager resolution, but which should succeed given implicit casting rules. The error is
error: incompatible types: '[]u8' and '[1]u8'
.In this example, the compiler should attempt to cast each prong expression to
[]const u8
because the result type is predetermined by the function's return type. No peer type resolution should occur.In this example, the compiler should attempt to cast each prong expression to
[]const u8
because the result type is predetermined by the explicit variable type. No peer type resolution should occur.The text was updated successfully, but these errors were encountered: