Commit cfdbe54d authored by Hugo Moreau's avatar Hugo Moreau
Browse files

Updated checktype using panic for triggering errors

All "os.Exit" have been replaced by "panic".

* transform/checktype.go
parent 99bf8316
package transform
import (
"fmt"
"go/ast"
"go/token"
"os"
)
/*
......@@ -34,47 +32,34 @@ func (t *TypeChecker) Pre(meta *Meta, v *Visitor) bool {
switch rhn := node.Rhs[i].(type) {
case *ast.BasicLit:
if rhn.Kind != token.INT {
fmt.Println("Non-integer values are not supported.")
fmt.Println("Identified type :", rhn.Kind)
os.Exit(1)
panic("Non-integer values are not supported.")
}
case *ast.CompositeLit:
fmt.Println("Arrays are not supported.")
os.Exit(1)
panic("Arrays are not supported.")
}
}
case *ast.ChanType:
fmt.Println("Channels are not supported.")
os.Exit(1)
panic("Channels are not supported.")
case *ast.Ident:
if node.Name == "panic" {
fmt.Println("Panics are not supported.")
os.Exit(1)
panic("Panics are not supported.")
}
case *ast.InterfaceType:
fmt.Println("Interfaces are not supported.")
os.Exit(1)
panic("Interfaces are not supported.")
case *ast.MapType:
fmt.Println("Maps are not supported.")
os.Exit(1)
panic("Maps are not supported.")
case *ast.SelectorExpr:
fmt.Println("Select are not supported.")
os.Exit(1)
panic("Select are not supported.")
case *ast.SliceExpr:
fmt.Println("Slices are not supported.")
os.Exit(1)
panic("Slices are not supported.")
case *ast.StarExpr:
fmt.Println("Pointers are not supported.")
os.Exit(1)
panic("Pointers are not supported.")
case *ast.StructType:
fmt.Println("Structs are not supported.")
os.Exit(1)
panic("Structs are not supported.")
case *ast.SwitchStmt:
fmt.Println("Switch are not supported.")
os.Exit(1)
panic("Switch are not supported.")
case *ast.UnaryExpr:
fmt.Println("Pointers are not supported.")
os.Exit(1)
panic("Pointers are not supported.")
}
return true
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment