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) {
|
func TestSwitchErrNotConstant (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"y cannot represent a constant integer", 7, 4,
|
"y is not constant", 7, 4,
|
||||||
`
|
`
|
||||||
[f x:Int]:Int = {
|
[f x:Int]:Int = {
|
||||||
y:Int = 1
|
y:Int = 1
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package analyzer
|
package analyzer
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "git.tebibyte.media/fspl/fspl/eval"
|
||||||
import "git.tebibyte.media/fspl/fspl/errors"
|
import "git.tebibyte.media/fspl/fspl/errors"
|
||||||
import "git.tebibyte.media/fspl/fspl/entity"
|
import "git.tebibyte.media/fspl/fspl/entity"
|
||||||
import "git.tebibyte.media/fspl/fspl/parser/fspl"
|
import "git.tebibyte.media/fspl/fspl/parser/fspl"
|
||||||
@ -898,10 +899,11 @@ func (this *Tree) analyzeSwitch (
|
|||||||
cas.Expression = expression
|
cas.Expression = expression
|
||||||
this.popScope()
|
this.popScope()
|
||||||
|
|
||||||
|
key, err = eval.EvaluateConstant(key)
|
||||||
|
if err != nil { return nil, err }
|
||||||
|
|
||||||
var keyInt int64
|
var keyInt int64
|
||||||
switch key := key.(type) {
|
switch key := key.(type) {
|
||||||
// TODO: once constant expression evaluation has been
|
|
||||||
// implemented, add constants here
|
|
||||||
case *entity.LiteralInt:
|
case *entity.LiteralInt:
|
||||||
keyInt = int64(key.Value)
|
keyInt = int64(key.Value)
|
||||||
case *entity.LiteralString:
|
case *entity.LiteralString:
|
||||||
|
Loading…
Reference in New Issue
Block a user