Beef
Beef copied to clipboard
Unassigned variable is usable in a specific context
While trying to fix an IDE crash that I encountered (https://github.com/beefytech/Beef/pull/1429), I found out that the cause of the issue is because Beef currently allows an unassigned variable to be used if that usage comes after an enum union matching.
Example code:
public static Result<int64> Test64()
{
return .Err;
}
public static int Main(String[] args)
{
int64 i64;
if (Test64() case .Ok(out i64))
{
}
Console.WriteLine(i64); // no error
return 0;
}
I noticed that this issue was already fixed, but I found two more issues similar to the old one:
Code with comments describing the issues:
Result<String> str()
{
return .Err;
}
for (int i < 10)
{
String s;
#if true // Issue 1
// This shouldn't fix the unassigned error
if (str() case .Ok(out s) || s == null) // s shouldn't be usable after enum matching failed
{
Console.WriteLine(s);
continue;
}
#endif
#if false // Issue 2
// This shouldn't cause the unassigned error in Console.WriteLine
if (true || !(str() case .Ok(out s)))
{
continue;
}
#endif
Console.WriteLine(s);
}