Open polamoros opened 7 months ago
Internally, this is probably related to the compiler creating an environment for user defined types with the environment name as the identifier to detect duplicates.
We may be able to support that by prefixing the environment name with the type (?).
That said, I'm not sure we actually want to allow a Struct
and a Class
having the same name, as it may lead to confusing code, so I'm not sure this is a bug.
This is different from #1635 which would should probably solve.
WDYT?
I think it's ok to treat this as a bug. I understand it's a little weird having a struct and class with the same name, but I believe it's unrelated to the struct-ness or class-ness of the types. For example, it's valid in Wing to have two classes with the same name:
// subdir1/index.w
pub class Foo {}
// subdir2/index.w
pub class Foo {}
// main.w
bring "./subdir1" as foo1;
bring "./subdir2" as foo2;
new foo1.Foo();
new foo2.Foo();
I think the example by Pol should work since he is directly importing each file and assigning each as an alias. BUT, if he tried compiling the example as a library, it should fail since the types are in the same directory:
// foo.w
pub class Foo {}
// bar.w
pub struct Foo {}
I think the error message should be something like
$ wing pack
error: running "wing compile ./" failed
error: public type Foo is defined more than once in directory "./"
But those are just my current thoughts, it's possible there are better solutions
Hi,
This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
I tried this:
This happened:
I expected this:
To be able to use the same identifier in separated contexts.
and/or
The error to include paths to both files.
Is there a workaround?
No response
Anything else?
No response
Wing Version
No response
Node.js Version
No response
Platform(s)
No response
Community Notes