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

pass triggering errors for use of channels

parent 05ddb503
package main
import "fmt"
func sum(s []int, c chan int) {
sum := 0
for _, v := range s {
sum += v
}
c <- sum // send sum to c
}
func main() {
s := []int{7, 2, 8, -9, 4, 0}
c := make(chan int)
go sum(s[:len(s)/2], c)
go sum(s[len(s)/2:], c)
x, y := <-c, <-c // receive from c
fmt.Println(x, y, x+y)
}
......@@ -8,8 +8,9 @@ import (
)
/*
The TypeChecker check if there is other types, variable must be declared
as integer.
The TypeChecker triggers errors for uses of :
- Non-integer variable
- Channel
*/
type TypeChecker struct {
......@@ -24,12 +25,15 @@ 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("Values must be integer.")
fmt.Println("Non-integer values are not supported.")
fmt.Println("Identified type :", rhn.Kind)
os.Exit(1)
}
}
}
case *ast.ChanType:
fmt.Println("Channels are not supported.")
os.Exit(1)
}
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