From 4f64bf86e53a4dc34dd997e30dc4040aa73b88e9 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 30 Jun 2020 10:41:45 +0300 Subject: [PATCH] compiler: add test for argument shadowing Thanks @roman-khimov. --- pkg/compiler/global_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/compiler/global_test.go b/pkg/compiler/global_test.go index 99ca986ac..8b98761d3 100644 --- a/pkg/compiler/global_test.go +++ b/pkg/compiler/global_test.go @@ -83,3 +83,25 @@ func TestShadow(t *testing.T) { t.Run("Switch", runCase("switch true {\ncase false: x += 2\ncase true:")) t.Run("Block", runCase("{")) } + +func TestArgumentLocal(t *testing.T) { + srcTmpl := `package foo + func some(a int) int { + if a > 42 { + a := 24 + _ = a + } + return a + } + func Main() int { + return some(%d) + }` + t.Run("Override", func(t *testing.T) { + src := fmt.Sprintf(srcTmpl, 50) + eval(t, src, big.NewInt(50)) + }) + t.Run("NoOverride", func(t *testing.T) { + src := fmt.Sprintf(srcTmpl, 40) + eval(t, src, big.NewInt(40)) + }) +}