cx
cx copied to clipboard
ambiguous referencing same-named funcs from imported packages
@0pcom commented on Aug 9
Describe the bug
A cx program is defined which contains reference to functions with the same name from imported packages:
package main
import "foo"
import "bar"
import "xyzzy"
func main () {
xyzzy.testprint()
}
package foo
func test1 () {
str.print("Hello World!")
}
package bar
func test1 () {
str.print("Goodbye World!")
}
package xyzzy
import "main"
func testprint () {
main.test1()
}
The result of this program depends on the order the packages are imported
This is non-desireable or ambiguous behavior
To Reproduce run the above program
Expected behavior The program should probably display an error in the case that a func (rather, a pointer to a func name) is redefined by a subsequently imported package.
In lieu of that, It might be better if it was required to directly reference a package function, rather than just referencing main or another package which has already imported the requisite packages.
Desktop
- OS: Linux
- CX Version 0.7.1
Additional context
This behavior is different for vars than funcs
package main
import "bar"
import "foo"
import "xyzzy"
func main () {
xyzzy.testprint()
}
package foo
var string1 str = "Hello World!"
package bar
var string1 str = "Goodbye World!"
package xyzzy
import "main"
func testprint () {
str.print(sprintf("String 1: %s", main.string1))
}
when run gives:
panic: struct 'string1' not found in package 'main'
it appears while vars must be directly referenced, funcs can be referenced by proxy (i.e. referencing a package which has imported a package containing the func)
First part of code, does not give error.
But second Additional context
code produces same error.
Can't call main.string1
, but foo.string1
works