Skip to content

Commit

Permalink
fix const name collision
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Jun 2, 2024
1 parent f3e4e31 commit a729023
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/xgo/runtime_gen/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.38"
const REVISION = "04f19fc3545957ade879144d189553b48be40419+1"
const NUMBER = 255
const REVISION = "f3e4e310320226a1de91a82ea3555dd28c7f306a+1"
const NUMBER = 256

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import "fmt"

const VERSION = "1.0.38"
const REVISION = "04f19fc3545957ade879144d189553b48be40419+1"
const NUMBER = 255
const REVISION = "f3e4e310320226a1de91a82ea3555dd28c7f306a+1"
const NUMBER = 256

func getRevision() string {
revSuffix := ""
Expand Down
9 changes: 9 additions & 0 deletions patch/syntax/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,17 @@ func (ctx *BlockContext) traverseDecl(node syntax.Decl, globaleNames map[string]
}
switch node := node.(type) {
case *syntax.ConstDecl:
for _, name := range node.NameList {
ctx.Add(name.Value)
}
case *syntax.TypeDecl:
if node.Name != nil {
ctx.Add(node.Name.Value)
}
case *syntax.VarDecl:
for _, name := range node.NameList {
ctx.Add(name.Value)
}
// var a int64 = N
if node.Values != nil {
if ctx.RHSVarDeclParent == nil {
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.38"
const REVISION = "04f19fc3545957ade879144d189553b48be40419+1"
const NUMBER = 255
const REVISION = "f3e4e310320226a1de91a82ea3555dd28c7f306a+1"
const NUMBER = 256

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
14 changes: 13 additions & 1 deletion runtime/test/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ import (
"testing"
)

func TestArrayPointer(t *testing.T) {
const (
pod1 = "pod1"
)

type Pod struct {
Name string
}

func TestConstNameCollision(t *testing.T) {
var pod1 *Pod

if pod1 != nil && pod1.Name != "" {
t.Fatalf("pod1 should be empty")
}
}
17 changes: 17 additions & 0 deletions runtime/test/trap/trap_var_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,20 @@ func TestArrayPointer(t *testing.T) {
t.Fatalf("expect a to be 100ms, actual: %v", calcTime)
}
}

const (
pod1 = "pod1"
)

type Pod struct {
Name string
}

// see bug https://github.com/xhd2015/xgo/issues/183
func TestConstNameCollision(t *testing.T) {
var pod1 *Pod

if pod1 != nil && pod1.Name != "" {
t.Fatalf("pod1 should be empty")
}
}

0 comments on commit a729023

Please sign in to comment.