Ok we have:
p1\Main.scala
package p1
import scala.collection.mutable.ArrayBuffer
class Table {
val rows = new ArrayBuffer[Row]
def add(r: Row): Unit = rows += r
override def toString = rows.mkString("Table(", ", ", ")")
}
class Row {
val cells = new ArrayBuffer[Cell]
def add(c: Cell): Unit = cells += c
override def toString = cells.mkString("Row(", ", ", ")")
}
case class Cell(elem: String)
object HtmlTable{
def htmlTable(init: implicit Table => Unit) = {
implicit val t = new Table
init
t
}
def row(init: implicit Row => Unit)(implicit t: Table) = {
implicit val r = new Row
init
t.add(r)
}
def cell(str: String)(implicit r: Row) =
r.add(new Cell(str))
}
p3\Main.scala
package p3
import scala.collection.mutable.ArrayBuffer
class Table1 {
val rows = new ArrayBuffer[Row1]
def add(r: Row1): Unit = rows += r
override def toString = rows.mkString("Table(", ", ", ")")
}
class Row1 {
val cells = new ArrayBuffer[Cell1]
def add(c: Cell1): Unit = cells += c
override def toString = cells.mkString("Row(", ", ", ")")
}
case class Cell1(elem: String)
object ExcelTable{
def excelTable(init: implicit Table1 => Unit) = {
implicit val t = new Table1
init
t
}
def row(init: implicit Row1 => Unit)(implicit t: Table1) = {
implicit val r = new Row1
init
t.add(r)
}
def cell(str: String)(implicit r: Row1) =
r.add(new Cell1(str))
}
p2\main.scala
object Test{
def main():Unit = {
import p3.ExcelTable._ // it does not work without that
//import p1.Dsl.table // it is not enough
excelTable {
row {
cell("top left")
cell("top right")
}
row {
cell("bottom left")
cell("bottom right")
}
}
//It does not work in this context
import p1.HtmlTable._
htmlTable {
row {
cell("top left")
cell("top right")
}
row {
cell("bottom left")
cell("bottom right")
}
}
}
}
And we have compilation error
[info] Compiling 1 Scala source to C:\buf\dotty\sample\target\scala-0.8\classes ...
[error] -- [E049] Reference Error: C:\buf\dotty\sample\src\main\scala\p2\Main.scala:19:10
[error] 19 | row {
[error] | ^^^
[error] | reference to `row` is ambiguous
[error] | it is both imported by import p3.ExcelTable._
[error] | and imported subsequently by import p1.HtmlTable._
[error] -- [E049] Reference Error: C:\buf\dotty\sample\src\main\scala\p2\Main.scala:20:12
[error] 20 | cell("top left")
If we try to work with these tables simultaneously