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
Currently cgen uses C ternary expression to generate a match expression which returns a value. The disadvantage of the ternary operator is, that it doesn't support variables which results in no it variable on SumTypes and in general no variables in the body.
Not working example:
// sumtypea:=match b {
c { it.foo }
else { placeholdervalue }
}
The solution for this would be to use common if-else generation.
There is another Problem with this.
Let's say, the match expr assigns the result to a variable.
Then cgen generates an output of string myRes =. After this output comes the ternary operator, normally.
To return something using if and else we have to use a temp-variable. But because our myRes variable is defined before, there is no way to assign the value to it.
The perfect result of a match-expr would look like this:
typeAbc=int|stringstructFoo {
bar string
}
fnfoo(bar string) {}
fnmain() {
a:=Abc(1)
len:=match a {
int { 'asdsad' }
string { a }
}
x:= Foo{
bar: match a {
int { 'asdsad' }
string { a }
}
}
// vlib/time/format.v:140foo(match a {
int { 'asdsad' }
string { a }
})
}
The text was updated successfully, but these errors were encountered:
Currently cgen uses C ternary expression to generate a match expression which returns a value. The disadvantage of the ternary operator is, that it doesn't support variables which results in no
it
variable on SumTypes and in general no variables in the body.Not working example:
The solution for this would be to use common
if
-else
generation.There is another Problem with this.
Let's say, the match expr assigns the result to a variable.
Then cgen generates an output of
string myRes =
. After this output comes the ternary operator, normally.To return something using if and else we have to use a temp-variable. But because our
myRes
variable is defined before, there is no way to assign the value to it.The perfect result of a match-expr would look like this:
Currently there is no way to get this result.
This should work:
The text was updated successfully, but these errors were encountered: