Switch statements now evaluate constants
This commit is contained in:
parent
e104da363c
commit
8248135255
|
@ -144,7 +144,7 @@ testStringErr (test,
|
|||
|
||||
func TestSwitchErrNotConstant (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"y cannot represent a constant integer", 7, 4,
|
||||
"y is not constant", 7, 4,
|
||||
`
|
||||
[f x:Int]:Int = {
|
||||
y:Int = 1
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package analyzer
|
||||
|
||||
import "fmt"
|
||||
import "git.tebibyte.media/fspl/fspl/eval"
|
||||
import "git.tebibyte.media/fspl/fspl/errors"
|
||||
import "git.tebibyte.media/fspl/fspl/entity"
|
||||
import "git.tebibyte.media/fspl/fspl/parser/fspl"
|
||||
|
@ -897,11 +898,12 @@ func (this *Tree) analyzeSwitch (
|
|||
if err != nil { this.popScope(); return nil, err }
|
||||
cas.Expression = expression
|
||||
this.popScope()
|
||||
|
||||
key, err = eval.EvaluateConstant(key)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
var keyInt int64
|
||||
switch key := key.(type) {
|
||||
// TODO: once constant expression evaluation has been
|
||||
// implemented, add constants here
|
||||
case *entity.LiteralInt:
|
||||
keyInt = int64(key.Value)
|
||||
case *entity.LiteralString:
|
||||
|
|
Loading…
Reference in New Issue