Skip to content

Commit d97bbab

Browse files
committed
gc: cmplx typecheck bug fix
Fixes golang#729. R=ken2 CC=golang-dev https://golang.org/cl/875048
1 parent 3ffbd57 commit d97bbab

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/cmd/gc/typecheck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ typecheck(Node **np, int top)
790790
defaultlit2(&l, &r, 0);
791791
n->left = l;
792792
n->right = r;
793-
if(l->type->etype != l->type->etype) {
793+
if(l->type->etype != r->type->etype) {
794794
badcmplx:
795795
yyerror("invalid operation: %#N (cmplx of types %T, %T)", n, l->type, r->type);
796796
goto error;

test/cmplx.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// errchk $G -e $D/$F.go
2+
3+
// Copyright 2010 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
var (
10+
f float
11+
f32 float32
12+
f64 float64
13+
14+
c complex
15+
c64 complex64
16+
c128 complex128
17+
)
18+
19+
func main() {
20+
// ok
21+
c = cmplx(f, f)
22+
c64 = cmplx(f32, f32)
23+
c128 = cmplx(f64, f64)
24+
25+
_ = cmplx(f, f32) // ERROR "cmplx"
26+
_ = cmplx(f, f64) // ERROR "cmplx"
27+
_ = cmplx(f32, f) // ERROR "cmplx"
28+
_ = cmplx(f32, f64) // ERROR "cmplx"
29+
_ = cmplx(f64, f) // ERROR "cmplx"
30+
_ = cmplx(f64, f32) // ERROR "cmplx"
31+
}

0 commit comments

Comments
 (0)