File tree 4 files changed +22
-1
lines changed
4 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 3
3
// license that can be found in the LICENSE file.
4
4
5
5
// Failed to add type conversion for negative constant.
6
+ // Issue 28772: Failed to add type conversion for Go constant set to C constant.
6
7
// No runtime test; just make sure it compiles.
7
8
8
9
package cgotest
9
10
10
11
/*
11
12
#include <complex.h>
12
13
14
+ #define issue28772Constant 1
15
+
13
16
static void issue28545F(char **p, int n, complex double a) {}
14
17
*/
15
18
import "C"
16
19
20
+ const issue28772Constant = C .issue28772Constant
21
+
17
22
func issue28545G (p * * C.char ) {
18
23
C .issue28545F (p , - 1 , (0 ))
19
24
C .issue28545F (p , 2 + 3 , complex (1 , 1 ))
25
+ C .issue28545F (p , issue28772Constant , (0 ))
20
26
}
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ func (f *File) ParseGo(name string, src []byte) {
66
66
f .Package = ast1 .Name .Name
67
67
f .Name = make (map [string ]* Name )
68
68
f .NamePos = make (map [* Name ]token.Pos )
69
+ f .Consts = make (map [string ]bool )
69
70
70
71
// In ast1, find the import "C" line and get any extra C preamble.
71
72
sawC := false
@@ -191,6 +192,18 @@ func (f *File) saveExprs(x interface{}, context astContext) {
191
192
}
192
193
case * ast.CallExpr :
193
194
f .saveCall (x , context )
195
+ case * ast.GenDecl :
196
+ if x .Tok == token .CONST {
197
+ for _ , spec := range x .Specs {
198
+ vs := spec .(* ast.ValueSpec )
199
+ if vs .Type == nil {
200
+ for _ , name := range spec .(* ast.ValueSpec ).Names {
201
+ f .Consts [name .Name ] = true
202
+ }
203
+ }
204
+ }
205
+ }
206
+
194
207
}
195
208
}
196
209
Original file line number Diff line number Diff line change @@ -1232,7 +1232,8 @@ func (p *Package) isConst(f *File, x ast.Expr) bool {
1232
1232
return x .Name == "nil" ||
1233
1233
strings .HasPrefix (x .Name , "_Ciconst_" ) ||
1234
1234
strings .HasPrefix (x .Name , "_Cfconst_" ) ||
1235
- strings .HasPrefix (x .Name , "_Csconst_" )
1235
+ strings .HasPrefix (x .Name , "_Csconst_" ) ||
1236
+ f .Consts [x .Name ]
1236
1237
case * ast.UnaryExpr :
1237
1238
return p .isConst (f , x .X )
1238
1239
case * ast.BinaryExpr :
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ type File struct {
62
62
Name map [string ]* Name // map from Go name to Name
63
63
NamePos map [* Name ]token.Pos // map from Name to position of the first reference
64
64
Edit * edit.Buffer
65
+ Consts map [string ]bool // untyped constants
65
66
}
66
67
67
68
func (f * File ) offset (p token.Pos ) int {
You can’t perform that action at this time.
0 commit comments