Skip to content

Commit

Permalink
Add globals_test
Browse files Browse the repository at this point in the history
  • Loading branch information
upamanyus committed Dec 18, 2024
1 parent cf3481d commit 69fd3fc
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions globals_test/globals.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

func foo() uint64 {
return 10
}

var GlobalX uint64 = foo()
var globalY string

var globalA, globalB = "a", "b"

func other() {
globalY = "ok"
}

func bar() {
other()
if GlobalX != 10 || globalY != "ok" {
panic("bad")
}
}

func init() {
GlobalX = GlobalX

Check failure on line 24 in globals_test/globals.go

View workflow job for this annotation

GitHub Actions / test (stable)

self-assignment of GlobalX to GlobalX
}

func init() {
globalY = ""
}

func main() {
bar()
}

0 comments on commit 69fd3fc

Please sign in to comment.