compiler: implement comparing channel values
Этот коммит содержится в:
родитель
c981f14e61
коммит
0a40219680
3 изменённых файлов: 5 добавлений и 3 удалений
|
@ -1953,10 +1953,12 @@ func (c *Compiler) parseBinOp(op token.Token, typ types.Type, x, y llvm.Value, p
|
||||||
default:
|
default:
|
||||||
return llvm.Value{}, c.makeError(pos, "binop on interface: "+op.String())
|
return llvm.Value{}, c.makeError(pos, "binop on interface: "+op.String())
|
||||||
}
|
}
|
||||||
case *types.Map, *types.Pointer:
|
case *types.Chan, *types.Map, *types.Pointer:
|
||||||
// Maps are in general not comparable, but can be compared against nil
|
// Maps are in general not comparable, but can be compared against nil
|
||||||
// (which is a nil pointer). This means they can be trivially compared
|
// (which is a nil pointer). This means they can be trivially compared
|
||||||
// by treating them as a pointer.
|
// by treating them as a pointer.
|
||||||
|
// Channels behave as pointers in that they are equal as long as they
|
||||||
|
// are created with the same call to make or if both are nil.
|
||||||
switch op {
|
switch op {
|
||||||
case token.EQL: // ==
|
case token.EQL: // ==
|
||||||
return c.builder.CreateICmp(llvm.IntEQ, x, y, ""), nil
|
return c.builder.CreateICmp(llvm.IntEQ, x, y, ""), nil
|
||||||
|
|
2
testdata/channel.go
предоставленный
2
testdata/channel.go
предоставленный
|
@ -4,7 +4,7 @@ import "time"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ch := make(chan int)
|
ch := make(chan int)
|
||||||
println("len, cap of channel:", len(ch), cap(ch))
|
println("len, cap of channel:", len(ch), cap(ch), ch == nil)
|
||||||
go sender(ch)
|
go sender(ch)
|
||||||
|
|
||||||
n, ok := <-ch
|
n, ok := <-ch
|
||||||
|
|
2
testdata/channel.txt
предоставленный
2
testdata/channel.txt
предоставленный
|
@ -1,4 +1,4 @@
|
||||||
len, cap of channel: 0 0
|
len, cap of channel: 0 0 false
|
||||||
recv from open channel: 1 true
|
recv from open channel: 1 true
|
||||||
received num: 2
|
received num: 2
|
||||||
received num: 3
|
received num: 3
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче