mill icon indicating copy to clipboard operation
mill copied to clipboard

In Mill 0.11, importing multiple projects with same filename leads to ambiguous import

Open sequencer opened this issue 1 year ago • 2 comments

We(the Chisel guys) are using Scala for building projects from sources. However when we imports multiple file, e.g:

import $file.someproject.common
import $file.anotherproject.common

These two common becomes ambiguous:

reference to common is ambiguous;
[error] it is imported twice in the same scope by
[error] import millbuild.someproject.common
[error] and import millbuild.anotherproject.common

Thanks to #2377, I'm able to see what happens, multiple common objects are defined as below:

package millbuild.someproject

object common extends common
class common extends _root_.mill.main.RootModule.Foreign(Some(_root_.mill.define.Segments.labels("foreign-modules", "someproject", "common")))

and

package millbuild.anotherproject
object common extends common
class common extends _root_.mill.main.RootModule.Foreign(Some(_root_.mill.define.Segments.labels("foreign-modules", "anotherproject", "common"))) 

These two are different object under different namespaces, but when using it from the main build script needs to workaround by using millbuild.someproject.common.SomeBuildModule, millbuild.anotherproject.common.AnotherBuildModule.

sequencer avatar Aug 04 '23 04:08 sequencer

This is expected Scala behavior. The solution is to rename at least n-1 ambiguous imports to disambiguate them.

import $file.someproject.{common => some}
import $file.anotherproject.{common => another}

lefou avatar Aug 04 '23 13:08 lefou

I tried this, however this seems not working.

sequencer avatar Aug 05 '23 07:08 sequencer