self types

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

self types

Bogdan Dumitriu
Hello all,

I'm been experimenting with scala and while implementing the examples
from "An Introduction to Scala"
(http://scala.epfl.ch/docu/files/ScalaIntro.pdf) I've ran into a
compilation problem. The problematic example is the one on pages 36-38,
which I reproduce below under the heading "file ExplicitThis.scala".
When compiling this using the scala 2.1.4 compiler I get a huge error
message which I also reproduce below under the heading "error message".

I've also noticed that bug #592
(http://scala-webapps.epfl.ch/bugtracking/bugs/displayItem.do?id=592)
seems to report a similar issue. Could anyone confirm that this is a
compiler bug and perhaps suggest a workaround? Or if there's something
wrong with my code, could someone point it out to me?

Many thanks,
Bogdan Dumitriu.

--- file ExplicitThis.scala

trait Graph {
  type Edge;
  type Node <: NodeIntf;

  trait NodeIntf {
    def connectWith(node: Node): Edge;
  }

  def nodes: List[Node];
  def edges: List[Edge];
  def addNode: Node;
}

abstract class DirectedGraph extends Graph {
  type Edge <: EdgeImpl;

  class EdgeImpl(origin: Node, dest: Node) {
    def from = origin;
    def to = dest;
  }

  class NodeImpl requires Node extends NodeIntf {
    def connectWith(node: Node): Edge = {
      val edge = newEdge(this, node);
      edges = edge :: edges;
      edge;
    }
  }

  protected def newNode: Node;
  protected def newEdge(from: Node, to: Node): Edge;
  var nodes: List[Node] = Nil;
  var edges: List[Edge] = Nil;

  def addNode: Node = {
    val node = newNode;
    nodes = node :: nodes;
    node;
  }
}

class ConcreteDirectedGraph extends DirectedGraph {
  type Edge = EdgeImpl;
  type Node = NodeImpl;

  protected def newNode: Node = {
    new NodeImpl;
  }

  protected def newEdge(f: Node, t: Node): Edge = {
    new EdgeImpl(f, t);
  }
}

object ExplicitThis {
  def main(args: Array[String]): Unit = {
    val g: Graph = new ConcreteDirectedGraph;
    val n1 = g.addNode;
    val n2 = g.addNode;
    val n3 = g.addNode;
    n1.connectWith(n2);
    n2.connectWith(n3);
    n1.connectWith(n3);
  }
}

--- error message

$ scalac ExplicitThis.scala
exception when transforming DirectedGraph.this.newEdge
exception when transforming DirectedGraph.this.newEdge(this, node)
exception when transforming val edge: DirectedGraph.this.Edge =
DirectedGraph.this.newEdge(this, node)
exception when transforming {
  val edge: DirectedGraph.this.Edge = DirectedGraph.this.newEdge(this,
node);
  DirectedGraph.this.edges_=({
    <synthetic> val x$0: DirectedGraph.this.Edge = edge;
    DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
  });
  edge
}
exception when transforming def connectWith(node:
DirectedGraph.this.Node): DirectedGraph.this.Edge = {
  val edge: DirectedGraph.this.Edge = DirectedGraph.this.newEdge(this,
node);
  DirectedGraph.this.edges_=({
    <synthetic> val x$0: DirectedGraph.this.Edge = edge;
    DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
  });
  edge
}
exception when transforming java.lang.Object with
DirectedGraph.this.NodeIntf with scala.ScalaObject {
  def this(): DirectedGraph.this.NodeImpl = {
    NodeImpl.super.this();
    ()
  };
  def connectWith(node: DirectedGraph.this.Node):
DirectedGraph.this.Edge = {
    val edge: DirectedGraph.this.Edge = DirectedGraph.this.newEdge(this,
node);
    DirectedGraph.this.edges_=({
      <synthetic> val x$0: DirectedGraph.this.Edge = edge;
      DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
    });
    edge
  };
  private <local> <paramaccessor> val $outer : DirectedGraph.this.type =
_;
  <stable> <accessor> <paramaccessor> def $outer():
DirectedGraph.this.type = NodeImpl.this.$outer
}
exception when transforming class NodeImplrequires
DirectedGraph.this.Node extends java.lang.Object with
DirectedGraph.this.NodeIntf with scala.ScalaObject {
  def this(): DirectedGraph.this.NodeImpl = {
    NodeImpl.super.this();
    ()
  };
  def connectWith(node: DirectedGraph.this.Node):
DirectedGraph.this.Edge = {
    val edge: DirectedGraph.this.Edge = DirectedGraph.this.newEdge(this,
node);
    DirectedGraph.this.edges_=({
      <synthetic> val x$0: DirectedGraph.this.Edge = edge;
      DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
    });
    edge
  }
}
exception when transforming java.lang.Object with Graph with
scala.ScalaObject {
  def this(): DirectedGraph = {
    DirectedGraph.super.this();
    ()
  };
  type Edge >: scala.All <: DirectedGraph.this.EdgeImpl;
  class EdgeImpl extends java.lang.Object with scala.ScalaObject {
    private <local> <paramaccessor> val origin: DirectedGraph.this.Node
= _;
    private <local> <paramaccessor> val dest: DirectedGraph.this.Node =
_;
    def this(origin: DirectedGraph.this.Node, dest:
DirectedGraph.this.Node): DirectedGraph.this.EdgeImpl = {
      EdgeImpl.super.this();
      ()
    };
    def from(): DirectedGraph.this.Node = EdgeImpl.this.origin;
    def to(): DirectedGraph.this.Node = EdgeImpl.this.dest
  };
  class NodeImplrequires DirectedGraph.this.Node extends
java.lang.Object with DirectedGraph.this.NodeIntf with
scala.ScalaObject {
    def this(): DirectedGraph.this.NodeImpl = {
      NodeImpl.super.this();
      ()
    };
    def connectWith(node: DirectedGraph.this.Node):
DirectedGraph.this.Edge = {
      val edge: DirectedGraph.this.Edge =
DirectedGraph.this.newEdge(this, node);
      DirectedGraph.this.edges_=({
        <synthetic> val x$0: DirectedGraph.this.Edge = edge;
        DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
      });
      edge
    }
  };
  protected def newNode(): DirectedGraph.this.Node;
  protected def newEdge(from: DirectedGraph.this.Node, to:
DirectedGraph.this.Node): DirectedGraph.this.Edge;
  private <local> var nodes : scala.List[DirectedGraph.this.Node] =
scala.Nil;
  <accessor> def nodes(): scala.List[DirectedGraph.this.Node] =
DirectedGraph.this.nodes ;
  <accessor> def nodes_=(x$1: scala.List[DirectedGraph.this.Node]):
scala.Unit = DirectedGraph.this.nodes  = x$1;
  private <local> var edges : scala.List[DirectedGraph.this.Edge] =
scala.Nil;
  <accessor> def edges(): scala.List[DirectedGraph.this.Edge] =
DirectedGraph.this.edges ;
  <accessor> def edges_=(x$1: scala.List[DirectedGraph.this.Edge]):
scala.Unit = DirectedGraph.this.edges  = x$1;
  def addNode(): DirectedGraph.this.Node = {
    val node: DirectedGraph.this.Node = DirectedGraph.this.newNode();
    DirectedGraph.this.nodes_=({
      <synthetic> val x$1: DirectedGraph.this.Node = node;
      DirectedGraph.this.nodes().::[DirectedGraph.this.Node](x$1)
    });
    node
  }
}
exception when transforming abstract class DirectedGraph extends
java.lang.Object with Graph with scala.ScalaObject {
  def this(): DirectedGraph = {
    DirectedGraph.super.this();
    ()
  };
  type Edge >: scala.All <: DirectedGraph.this.EdgeImpl;
  class EdgeImpl extends java.lang.Object with scala.ScalaObject {
    private <local> <paramaccessor> val origin: DirectedGraph.this.Node
= _;
    private <local> <paramaccessor> val dest: DirectedGraph.this.Node =
_;
    def this(origin: DirectedGraph.this.Node, dest:
DirectedGraph.this.Node): DirectedGraph.this.EdgeImpl = {
      EdgeImpl.super.this();
      ()
    };
    def from(): DirectedGraph.this.Node = EdgeImpl.this.origin;
    def to(): DirectedGraph.this.Node = EdgeImpl.this.dest
  };
  class NodeImplrequires DirectedGraph.this.Node extends
java.lang.Object with DirectedGraph.this.NodeIntf with
scala.ScalaObject {
    def this(): DirectedGraph.this.NodeImpl = {
      NodeImpl.super.this();
      ()
    };
    def connectWith(node: DirectedGraph.this.Node):
DirectedGraph.this.Edge = {
      val edge: DirectedGraph.this.Edge =
DirectedGraph.this.newEdge(this, node);
      DirectedGraph.this.edges_=({
        <synthetic> val x$0: DirectedGraph.this.Edge = edge;
        DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
      });
      edge
    }
  };
  protected def newNode(): DirectedGraph.this.Node;
  protected def newEdge(from: DirectedGraph.this.Node, to:
DirectedGraph.this.Node): DirectedGraph.this.Edge;
  private <local> var nodes : scala.List[DirectedGraph.this.Node] =
scala.Nil;
  <accessor> def nodes(): scala.List[DirectedGraph.this.Node] =
DirectedGraph.this.nodes ;
  <accessor> def nodes_=(x$1: scala.List[DirectedGraph.this.Node]):
scala.Unit = DirectedGraph.this.nodes  = x$1;
  private <local> var edges : scala.List[DirectedGraph.this.Edge] =
scala.Nil;
  <accessor> def edges(): scala.List[DirectedGraph.this.Edge] =
DirectedGraph.this.edges ;
  <accessor> def edges_=(x$1: scala.List[DirectedGraph.this.Edge]):
scala.Unit = DirectedGraph.this.edges  = x$1;
  def addNode(): DirectedGraph.this.Node = {
    val node: DirectedGraph.this.Node = DirectedGraph.this.newNode();
    DirectedGraph.this.nodes_=({
      <synthetic> val x$1: DirectedGraph.this.Node = node;
      DirectedGraph.this.nodes().::[DirectedGraph.this.Node](x$1)
    });
    node
  }
}
exception when transforming package <empty> {
  abstract trait Graph extends java.lang.Object with scala.ScalaObject {
    type Edge >: scala.All <: scala.Any;
    type Node >: scala.All <: Graph.this.NodeIntf;
    abstract trait NodeIntf extends java.lang.Object with
scala.ScalaObject {
      def connectWith(node: Graph.this.Node): Graph.this.Edge
    };
    def nodes(): scala.List[Graph.this.Node];
    def edges(): scala.List[Graph.this.Edge];
    def addNode(): Graph.this.Node
  };
  abstract class DirectedGraph extends java.lang.Object with Graph with
scala.ScalaObject {
    def this(): DirectedGraph = {
      DirectedGraph.super.this();
      ()
    };
    type Edge >: scala.All <: DirectedGraph.this.EdgeImpl;
    class EdgeImpl extends java.lang.Object with scala.ScalaObject {
      private <local> <paramaccessor> val origin:
DirectedGraph.this.Node = _;
      private <local> <paramaccessor> val dest: DirectedGraph.this.Node
= _;
      def this(origin: DirectedGraph.this.Node, dest:
DirectedGraph.this.Node): DirectedGraph.this.EdgeImpl = {
        EdgeImpl.super.this();
        ()
      };
      def from(): DirectedGraph.this.Node = EdgeImpl.this.origin;
      def to(): DirectedGraph.this.Node = EdgeImpl.this.dest
    };
    class NodeImplrequires DirectedGraph.this.Node extends
java.lang.Object with DirectedGraph.this.NodeIntf with
scala.ScalaObject {
      def this(): DirectedGraph.this.NodeImpl = {
        NodeImpl.super.this();
        ()
      };
      def connectWith(node: DirectedGraph.this.Node):
DirectedGraph.this.Edge = {
        val edge: DirectedGraph.this.Edge =
DirectedGraph.this.newEdge(this, node);
        DirectedGraph.this.edges_=({
          <synthetic> val x$0: DirectedGraph.this.Edge = edge;
          DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
        });
        edge
      }
    };
    protected def newNode(): DirectedGraph.this.Node;
    protected def newEdge(from: DirectedGraph.this.Node, to:
DirectedGraph.this.Node): DirectedGraph.this.Edge;
    private <local> var nodes : scala.List[DirectedGraph.this.Node] =
scala.Nil;
    <accessor> def nodes(): scala.List[DirectedGraph.this.Node] =
DirectedGraph.this.nodes ;
    <accessor> def nodes_=(x$1: scala.List[DirectedGraph.this.Node]):
scala.Unit = DirectedGraph.this.nodes  = x$1;
    private <local> var edges : scala.List[DirectedGraph.this.Edge] =
scala.Nil;
    <accessor> def edges(): scala.List[DirectedGraph.this.Edge] =
DirectedGraph.this.edges ;
    <accessor> def edges_=(x$1: scala.List[DirectedGraph.this.Edge]):
scala.Unit = DirectedGraph.this.edges  = x$1;
    def addNode(): DirectedGraph.this.Node = {
      val node: DirectedGraph.this.Node = DirectedGraph.this.newNode();
      DirectedGraph.this.nodes_=({
        <synthetic> val x$1: DirectedGraph.this.Node = node;
        DirectedGraph.this.nodes().::[DirectedGraph.this.Node](x$1)
      });
      node
    }
  };
  class ConcreteDirectedGraph extends DirectedGraph with
scala.ScalaObject {
    def this(): ConcreteDirectedGraph = {
      ConcreteDirectedGraph.super.this();
      ()
    };
    type Edge = ConcreteDirectedGraph.this.EdgeImpl;
    type Node = ConcreteDirectedGraph.this.NodeImpl;
    protected def newNode(): ConcreteDirectedGraph.this.NodeImpl = new
ConcreteDirectedGraph.this.NodeImpl.this();
    protected def newEdge(f: ConcreteDirectedGraph.this.NodeImpl, t:
ConcreteDirectedGraph.this.NodeImpl):
ConcreteDirectedGraph.this.EdgeImpl = new
ConcreteDirectedGraph.this.EdgeImpl.this(f, t)
  };
  final class ExplicitThis extends java.lang.Object with
scala.ScalaObject {
    def this(): ExplicitThis = {
      ExplicitThis.super.this();
      ()
    };
    def main(args: scala.Array[java.lang.String]): scala.Unit = {
      val g: Graph = new ConcreteDirectedGraph.this();
      val n1: g.Node = g.addNode();
      val n2: g.Node = g.addNode();
      val n3: g.Node = g.addNode();
      n1.connectWith(n2);
      n2.connectWith(n3);
      {
        n1.connectWith(n3);
        ()
      }
    }
  }
}
Exception in thread "main" java.lang.Error: assertion failed:
NodeImpl.this.type
        at scala.Predef$.assert(Predef.scala:171)
        at
scala.tools.nsc.transform.ExplicitOuter.scala$tools$nsc$transform$ExplicitOuter$$outerMember(ExplicitOuter.scala:80)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.outerSelect(ExplicitOuter.scala:114)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.outerValue(ExplicitOuter.scala:100)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anon$0.transform(ExplicitOuter.scala:289)
        at
scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:1006)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:132)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anon$0.transform(ExplicitOuter.scala:311)
        at
scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:1000)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:132)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anon$0.transform(ExplicitOuter.scala:311)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$15.apply(Trees.scala:940)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$15.apply(Trees.scala:940)
        at
scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1046)
        at
scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:939)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:132)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anon$0.transform(ExplicitOuter.scala:311)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:1040)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:1038)
        at scala.List$.loop$0(List.scala:232)
        at scala.List$.mapConserve(List.scala:249)
        at
scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:1038)
        at
scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:966)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:132)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anon$0.transform(ExplicitOuter.scala:311)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$16.apply(Trees.scala:945)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$16.apply(Trees.scala:944)
        at
scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1046)
        at
scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:943)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:132)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anon$0.transform(ExplicitOuter.scala:311)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:1040)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:1038)
        at scala.List$.loop$0(List.scala:232)
        at scala.List$.mapConserve(List.scala:249)
        at scala.List$.loop$0(List.scala:236)
        at scala.List$.mapConserve(List.scala:249)
        at
scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:1038)
        at
scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:964)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:132)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anon$0.transform(ExplicitOuter.scala:311)
        at
scala.tools.nsc.ast.Trees$Transformer.transformTemplate(Trees.scala:1026)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$13.apply(Trees.scala:932)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$13.apply(Trees.scala:932)
        at
scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1046)
        at
scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:931)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:132)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anon$0.transform(ExplicitOuter.scala:311)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:1040)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:1038)
        at scala.List$.loop$0(List.scala:232)
        at scala.List$.mapConserve(List.scala:249)
        at scala.List$.loop$0(List.scala:236)
        at scala.List$.mapConserve(List.scala:249)
        at scala.List$.loop$0(List.scala:236)
        at scala.List$.mapConserve(List.scala:249)
        at
scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:1038)
        at
scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:964)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:132)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anon$0.transform(ExplicitOuter.scala:311)
        at
scala.tools.nsc.ast.Trees$Transformer.transformTemplate(Trees.scala:1026)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$13.apply(Trees.scala:932)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$13.apply(Trees.scala:932)
        at
scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1046)
        at
scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:931)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:132)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anon$0.transform(ExplicitOuter.scala:311)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:1040)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:1038)
        at scala.List$.loop$0(List.scala:232)
        at scala.List$.mapConserve(List.scala:249)
        at scala.List$.loop$0(List.scala:236)
        at scala.List$.mapConserve(List.scala:249)
        at
scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:1038)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$12.apply(Trees.scala:928)
        at
scala.tools.nsc.ast.Trees$Transformer$$anonfun$12.apply(Trees.scala:928)
        at
scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1046)
        at
scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:927)
        at
scala.tools.nsc.transform.ExplicitOuter$OuterPathTransformer.transform(ExplicitOuter.scala:132)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anon$0.transform(ExplicitOuter.scala:311)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anonfun$7.apply(ExplicitOuter.scala:357)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$$anonfun$7.apply(ExplicitOuter.scala:357)
        at
scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:38)
        at
scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:356)
        at
scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:1041)
        at
scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:22)
        at
scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:210)
        at
scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:199)
        at
scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:199)
        at scala.Iterator$class.foreach(Iterator.scala:285)
        at
scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:216)
        at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:199)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:429)
        at scala.tools.nsc.Global$Run.compile(Global.scala:487)
        at scala.tools.nsc.Main$.process(Main.scala:60)
        at scala.tools.nsc.Main$.main(Main.scala:82)
        at scala.tools.nsc.Main.main(Main.scala)
Reply | Threaded
Open this post in threaded view
|

Re: self types

sean.mcdirmid
Hi Bogdan,

Its definitely a bug we know about although I don't know how long it  
will take to fix. Thanks for your example, I've added it to the bug  
report as mine was way too big to fit in one page. As a temporary  
workaround, I'm currently using implicit coercions and an explicit  
self def. E.g.,

trait NodeIntf {
   def self : Node;
   def connectWith(node : Node): Edge;
}
implicit def convert(node : NodeIntf) = node.self;

Then ...

class ConcreteDirectedGraph extends DirectedGraph {
   type Node = NodeImpl0;

   class NodeImpl0 extends NodeImpl {
     def self = this;
   }
   // instantiate NodeImpl0 instead of NodeImpl.



Should do the trick in most cases. Of course, this just a temporary  
fix until requires works again.

Thanks again for your bug report.

Sean



On May 15, 2006, at 6:03 PM, Bogdan Dumitriu wrote:

> Hello all,
>
> I'm been experimenting with scala and while implementing the examples
> from "An Introduction to Scala"
> (http://scala.epfl.ch/docu/files/ScalaIntro.pdf) I've ran into a
> compilation problem. The problematic example is the one on pages  
> 36-38,
> which I reproduce below under the heading "file ExplicitThis.scala".
> When compiling this using the scala 2.1.4 compiler I get a huge error
> message which I also reproduce below under the heading "error  
> message".
>
> I've also noticed that bug #592
> (http://scala-webapps.epfl.ch/bugtracking/bugs/displayItem.do?id=592)
> seems to report a similar issue. Could anyone confirm that this is a
> compiler bug and perhaps suggest a workaround? Or if there's something
> wrong with my code, could someone point it out to me?
>
> Many thanks,
> Bogdan Dumitriu.
>
> --- file ExplicitThis.scala
>
> trait Graph {
>   type Edge;
>   type Node <: NodeIntf;
>
>   trait NodeIntf {
>     def connectWith(node: Node): Edge;
>   }
>
>   def nodes: List[Node];
>   def edges: List[Edge];
>   def addNode: Node;
> }
>
> abstract class DirectedGraph extends Graph {
>   type Edge <: EdgeImpl;
>
>   class EdgeImpl(origin: Node, dest: Node) {
>     def from = origin;
>     def to = dest;
>   }
>
>   class NodeImpl requires Node extends NodeIntf {
>     def connectWith(node: Node): Edge = {
>       val edge = newEdge(this, node);
>       edges = edge :: edges;
>       edge;
>     }
>   }
>
>   protected def newNode: Node;
>   protected def newEdge(from: Node, to: Node): Edge;
>   var nodes: List[Node] = Nil;
>   var edges: List[Edge] = Nil;
>
>   def addNode: Node = {
>     val node = newNode;
>     nodes = node :: nodes;
>     node;
>   }
> }
>
> class ConcreteDirectedGraph extends DirectedGraph {
>   type Edge = EdgeImpl;
>   type Node = NodeImpl;
>
>   protected def newNode: Node = {
>     new NodeImpl;
>   }
>
>   protected def newEdge(f: Node, t: Node): Edge = {
>     new EdgeImpl(f, t);
>   }
> }
>
> object ExplicitThis {
>   def main(args: Array[String]): Unit = {
>     val g: Graph = new ConcreteDirectedGraph;
>     val n1 = g.addNode;
>     val n2 = g.addNode;
>     val n3 = g.addNode;
>     n1.connectWith(n2);
>     n2.connectWith(n3);
>     n1.connectWith(n3);
>   }
> }
>
> --- error message
>
> $ scalac ExplicitThis.scala
> exception when transforming DirectedGraph.this.newEdge
> exception when transforming DirectedGraph.this.newEdge(this, node)
> exception when transforming val edge: DirectedGraph.this.Edge =
> DirectedGraph.this.newEdge(this, node)
> exception when transforming {
>   val edge: DirectedGraph.this.Edge = DirectedGraph.this.newEdge(this,
> node);
>   DirectedGraph.this.edges_=({
>     <synthetic> val x$0: DirectedGraph.this.Edge = edge;
>     DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
>   });
>   edge
> }
> exception when transforming def connectWith(node:
> DirectedGraph.this.Node): DirectedGraph.this.Edge = {
>   val edge: DirectedGraph.this.Edge = DirectedGraph.this.newEdge(this,
> node);
>   DirectedGraph.this.edges_=({
>     <synthetic> val x$0: DirectedGraph.this.Edge = edge;
>     DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
>   });
>   edge
> }
> exception when transforming java.lang.Object with
> DirectedGraph.this.NodeIntf with scala.ScalaObject {
>   def this(): DirectedGraph.this.NodeImpl = {
>     NodeImpl.super.this();
>     ()
>   };
>   def connectWith(node: DirectedGraph.this.Node):
> DirectedGraph.this.Edge = {
>     val edge: DirectedGraph.this.Edge = DirectedGraph.this.newEdge
> (this,
> node);
>     DirectedGraph.this.edges_=({
>       <synthetic> val x$0: DirectedGraph.this.Edge = edge;
>       DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
>     });
>     edge
>   };
>   private <local> <paramaccessor> val $outer :  
> DirectedGraph.this.type =
> _;
>   <stable> <accessor> <paramaccessor> def $outer():
> DirectedGraph.this.type = NodeImpl.this.$outer
> }
> exception when transforming class NodeImplrequires
> DirectedGraph.this.Node extends java.lang.Object with
> DirectedGraph.this.NodeIntf with scala.ScalaObject {
>   def this(): DirectedGraph.this.NodeImpl = {
>     NodeImpl.super.this();
>     ()
>   };
>   def connectWith(node: DirectedGraph.this.Node):
> DirectedGraph.this.Edge = {
>     val edge: DirectedGraph.this.Edge = DirectedGraph.this.newEdge
> (this,
> node);
>     DirectedGraph.this.edges_=({
>       <synthetic> val x$0: DirectedGraph.this.Edge = edge;
>       DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
>     });
>     edge
>   }
> }
> exception when transforming java.lang.Object with Graph with
> scala.ScalaObject {
>   def this(): DirectedGraph = {
>     DirectedGraph.super.this();
>     ()
>   };
>   type Edge >: scala.All <: DirectedGraph.this.EdgeImpl;
>   class EdgeImpl extends java.lang.Object with scala.ScalaObject {
>     private <local> <paramaccessor> val origin:  
> DirectedGraph.this.Node
> = _;
>     private <local> <paramaccessor> val dest:  
> DirectedGraph.this.Node =
> _;
>     def this(origin: DirectedGraph.this.Node, dest:
> DirectedGraph.this.Node): DirectedGraph.this.EdgeImpl = {
>       EdgeImpl.super.this();
>       ()
>     };
>     def from(): DirectedGraph.this.Node = EdgeImpl.this.origin;
>     def to(): DirectedGraph.this.Node = EdgeImpl.this.dest
>   };
>   class NodeImplrequires DirectedGraph.this.Node extends
> java.lang.Object with DirectedGraph.this.NodeIntf with
> scala.ScalaObject {
>     def this(): DirectedGraph.this.NodeImpl = {
>       NodeImpl.super.this();
>       ()
>     };
>     def connectWith(node: DirectedGraph.this.Node):
> DirectedGraph.this.Edge = {
>       val edge: DirectedGraph.this.Edge =
> DirectedGraph.this.newEdge(this, node);
>       DirectedGraph.this.edges_=({
>         <synthetic> val x$0: DirectedGraph.this.Edge = edge;
>         DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
>       });
>       edge
>     }
>   };
>   protected def newNode(): DirectedGraph.this.Node;
>   protected def newEdge(from: DirectedGraph.this.Node, to:
> DirectedGraph.this.Node): DirectedGraph.this.Edge;
>   private <local> var nodes : scala.List[DirectedGraph.this.Node] =
> scala.Nil;
>   <accessor> def nodes(): scala.List[DirectedGraph.this.Node] =
> DirectedGraph.this.nodes ;
>   <accessor> def nodes_=(x$1: scala.List[DirectedGraph.this.Node]):
> scala.Unit = DirectedGraph.this.nodes  = x$1;
>   private <local> var edges : scala.List[DirectedGraph.this.Edge] =
> scala.Nil;
>   <accessor> def edges(): scala.List[DirectedGraph.this.Edge] =
> DirectedGraph.this.edges ;
>   <accessor> def edges_=(x$1: scala.List[DirectedGraph.this.Edge]):
> scala.Unit = DirectedGraph.this.edges  = x$1;
>   def addNode(): DirectedGraph.this.Node = {
>     val node: DirectedGraph.this.Node = DirectedGraph.this.newNode();
>     DirectedGraph.this.nodes_=({
>       <synthetic> val x$1: DirectedGraph.this.Node = node;
>       DirectedGraph.this.nodes().::[DirectedGraph.this.Node](x$1)
>     });
>     node
>   }
> }
> exception when transforming abstract class DirectedGraph extends
> java.lang.Object with Graph with scala.ScalaObject {
>   def this(): DirectedGraph = {
>     DirectedGraph.super.this();
>     ()
>   };
>   type Edge >: scala.All <: DirectedGraph.this.EdgeImpl;
>   class EdgeImpl extends java.lang.Object with scala.ScalaObject {
>     private <local> <paramaccessor> val origin:  
> DirectedGraph.this.Node
> = _;
>     private <local> <paramaccessor> val dest:  
> DirectedGraph.this.Node =
> _;
>     def this(origin: DirectedGraph.this.Node, dest:
> DirectedGraph.this.Node): DirectedGraph.this.EdgeImpl = {
>       EdgeImpl.super.this();
>       ()
>     };
>     def from(): DirectedGraph.this.Node = EdgeImpl.this.origin;
>     def to(): DirectedGraph.this.Node = EdgeImpl.this.dest
>   };
>   class NodeImplrequires DirectedGraph.this.Node extends
> java.lang.Object with DirectedGraph.this.NodeIntf with
> scala.ScalaObject {
>     def this(): DirectedGraph.this.NodeImpl = {
>       NodeImpl.super.this();
>       ()
>     };
>     def connectWith(node: DirectedGraph.this.Node):
> DirectedGraph.this.Edge = {
>       val edge: DirectedGraph.this.Edge =
> DirectedGraph.this.newEdge(this, node);
>       DirectedGraph.this.edges_=({
>         <synthetic> val x$0: DirectedGraph.this.Edge = edge;
>         DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
>       });
>       edge
>     }
>   };
>   protected def newNode(): DirectedGraph.this.Node;
>   protected def newEdge(from: DirectedGraph.this.Node, to:
> DirectedGraph.this.Node): DirectedGraph.this.Edge;
>   private <local> var nodes : scala.List[DirectedGraph.this.Node] =
> scala.Nil;
>   <accessor> def nodes(): scala.List[DirectedGraph.this.Node] =
> DirectedGraph.this.nodes ;
>   <accessor> def nodes_=(x$1: scala.List[DirectedGraph.this.Node]):
> scala.Unit = DirectedGraph.this.nodes  = x$1;
>   private <local> var edges : scala.List[DirectedGraph.this.Edge] =
> scala.Nil;
>   <accessor> def edges(): scala.List[DirectedGraph.this.Edge] =
> DirectedGraph.this.edges ;
>   <accessor> def edges_=(x$1: scala.List[DirectedGraph.this.Edge]):
> scala.Unit = DirectedGraph.this.edges  = x$1;
>   def addNode(): DirectedGraph.this.Node = {
>     val node: DirectedGraph.this.Node = DirectedGraph.this.newNode();
>     DirectedGraph.this.nodes_=({
>       <synthetic> val x$1: DirectedGraph.this.Node = node;
>       DirectedGraph.this.nodes().::[DirectedGraph.this.Node](x$1)
>     });
>     node
>   }
> }
> exception when transforming package <empty> {
>   abstract trait Graph extends java.lang.Object with  
> scala.ScalaObject {
>     type Edge >: scala.All <: scala.Any;
>     type Node >: scala.All <: Graph.this.NodeIntf;
>     abstract trait NodeIntf extends java.lang.Object with
> scala.ScalaObject {
>       def connectWith(node: Graph.this.Node): Graph.this.Edge
>     };
>     def nodes(): scala.List[Graph.this.Node];
>     def edges(): scala.List[Graph.this.Edge];
>     def addNode(): Graph.this.Node
>   };
>   abstract class DirectedGraph extends java.lang.Object with Graph  
> with
> scala.ScalaObject {
>     def this(): DirectedGraph = {
>       DirectedGraph.super.this();
>       ()
>     };
>     type Edge >: scala.All <: DirectedGraph.this.EdgeImpl;
>     class EdgeImpl extends java.lang.Object with scala.ScalaObject {
>       private <local> <paramaccessor> val origin:
> DirectedGraph.this.Node = _;
>       private <local> <paramaccessor> val dest:  
> DirectedGraph.this.Node
> = _;
>       def this(origin: DirectedGraph.this.Node, dest:
> DirectedGraph.this.Node): DirectedGraph.this.EdgeImpl = {
>         EdgeImpl.super.this();
>         ()
>       };
>       def from(): DirectedGraph.this.Node = EdgeImpl.this.origin;
>       def to(): DirectedGraph.this.Node = EdgeImpl.this.dest
>     };
>     class NodeImplrequires DirectedGraph.this.Node extends
> java.lang.Object with DirectedGraph.this.NodeIntf with
> scala.ScalaObject {
>       def this(): DirectedGraph.this.NodeImpl = {
>         NodeImpl.super.this();
>         ()
>       };
>       def connectWith(node: DirectedGraph.this.Node):
> DirectedGraph.this.Edge = {
>         val edge: DirectedGraph.this.Edge =
> DirectedGraph.this.newEdge(this, node);
>         DirectedGraph.this.edges_=({
>           <synthetic> val x$0: DirectedGraph.this.Edge = edge;
>           DirectedGraph.this.edges().::[DirectedGraph.this.Edge](x$0)
>         });
>         edge
>       }
>     };
>     protected def newNode(): DirectedGraph.this.Node;
>     protected def newEdge(from: DirectedGraph.this.Node, to:
> DirectedGraph.this.Node): DirectedGraph.this.Edge;
>     private <local> var nodes : scala.List[DirectedGraph.this.Node] =
> scala.Nil;
>     <accessor> def nodes(): scala.List[DirectedGraph.this.Node] =
> DirectedGraph.this.nodes ;
>     <accessor> def nodes_=(x$1: scala.List[DirectedGraph.this.Node]):
> scala.Unit = DirectedGraph.this.nodes  = x$1;
>     private <local> var edges : scala.List[DirectedGraph.this.Edge] =
> scala.Nil;
>     <accessor> def edges(): scala.List[DirectedGraph.this.Edge] =
> DirectedGraph.this.edges ;
>     <accessor> def edges_=(x$1: scala.List[DirectedGraph.this.Edge]):
> scala.Unit = DirectedGraph.this.edges  = x$1;
>     def addNode(): DirectedGraph.this.Node = {
>       val node: DirectedGraph.this.Node = DirectedGraph.this.newNode
> ();
>       DirectedGraph.this.nodes_=({
>         <synthetic> val x$1: DirectedGraph.this.Node = node;
>         DirectedGraph.this.nodes().::[DirectedGraph.this.Node](x$1)
>       });
>       node
>     }
>   };
>   class ConcreteDirectedGraph extends DirectedGraph with
> scala.ScalaObject {
>     def this(): ConcreteDirectedGraph = {
>       ConcreteDirectedGraph.super.this();
>       ()
>     };
>     type Edge = ConcreteDirectedGraph.this.EdgeImpl;
>     type Node = ConcreteDirectedGraph.this.NodeImpl;
>     protected def newNode(): ConcreteDirectedGraph.this.NodeImpl = new
> ConcreteDirectedGraph.this.NodeImpl.this();
>     protected def newEdge(f: ConcreteDirectedGraph.this.NodeImpl, t:
> ConcreteDirectedGraph.this.NodeImpl):
> ConcreteDirectedGraph.this.EdgeImpl = new
> ConcreteDirectedGraph.this.EdgeImpl.this(f, t)
>   };
>   final class ExplicitThis extends java.lang.Object with
> scala.ScalaObject {
>     def this(): ExplicitThis = {
>       ExplicitThis.super.this();
>       ()
>     };
>     def main(args: scala.Array[java.lang.String]): scala.Unit = {
>       val g: Graph = new ConcreteDirectedGraph.this();
>       val n1: g.Node = g.addNode();
>       val n2: g.Node = g.addNode();
>       val n3: g.Node = g.addNode();
>       n1.connectWith(n2);
>       n2.connectWith(n3);
>       {
>         n1.connectWith(n3);
>         ()
>       }
>     }
>   }
> }
> Exception in thread "main" java.lang.Error: assertion failed:
> NodeImpl.this.type
>         at scala.Predef$.assert(Predef.scala:171)
>         at
> scala.tools.nsc.transform.ExplicitOuter.scala$tools$nsc$transform
> $ExplicitOuter$$outerMember(ExplicitOuter.scala:80)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.outerSelect(ExplicitOuter.scala:114)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.outerValue(ExplicitOuter.scala:100)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anon$0.transform(ExplicitOuter.scala:289)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:1006)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.transform(ExplicitOuter.scala:132)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anon$0.transform(ExplicitOuter.scala:311)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:1000)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.transform(ExplicitOuter.scala:132)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anon$0.transform(ExplicitOuter.scala:311)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$15.apply(Trees.scala:
> 940)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$15.apply(Trees.scala:
> 940)
>         at
> scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1046)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:939)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.transform(ExplicitOuter.scala:132)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anon$0.transform(ExplicitOuter.scala:311)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:
> 1040)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:
> 1038)
>         at scala.List$.loop$0(List.scala:232)
>         at scala.List$.mapConserve(List.scala:249)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:1038)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:966)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.transform(ExplicitOuter.scala:132)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anon$0.transform(ExplicitOuter.scala:311)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$16.apply(Trees.scala:
> 945)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$16.apply(Trees.scala:
> 944)
>         at
> scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1046)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:943)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.transform(ExplicitOuter.scala:132)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anon$0.transform(ExplicitOuter.scala:311)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:
> 1040)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:
> 1038)
>         at scala.List$.loop$0(List.scala:232)
>         at scala.List$.mapConserve(List.scala:249)
>         at scala.List$.loop$0(List.scala:236)
>         at scala.List$.mapConserve(List.scala:249)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:1038)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:964)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.transform(ExplicitOuter.scala:132)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anon$0.transform(ExplicitOuter.scala:311)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transformTemplate(Trees.scala:
> 1026)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$13.apply(Trees.scala:
> 932)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$13.apply(Trees.scala:
> 932)
>         at
> scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1046)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:931)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.transform(ExplicitOuter.scala:132)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anon$0.transform(ExplicitOuter.scala:311)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:
> 1040)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:
> 1038)
>         at scala.List$.loop$0(List.scala:232)
>         at scala.List$.mapConserve(List.scala:249)
>         at scala.List$.loop$0(List.scala:236)
>         at scala.List$.mapConserve(List.scala:249)
>         at scala.List$.loop$0(List.scala:236)
>         at scala.List$.mapConserve(List.scala:249)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:1038)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:964)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.transform(ExplicitOuter.scala:132)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anon$0.transform(ExplicitOuter.scala:311)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transformTemplate(Trees.scala:
> 1026)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$13.apply(Trees.scala:
> 932)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$13.apply(Trees.scala:
> 932)
>         at
> scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1046)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:931)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.transform(ExplicitOuter.scala:132)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anon$0.transform(ExplicitOuter.scala:311)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:
> 1040)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$25.apply(Trees.scala:
> 1038)
>         at scala.List$.loop$0(List.scala:232)
>         at scala.List$.mapConserve(List.scala:249)
>         at scala.List$.loop$0(List.scala:236)
>         at scala.List$.mapConserve(List.scala:249)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:1038)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$12.apply(Trees.scala:
> 928)
>         at
> scala.tools.nsc.ast.Trees$Transformer$$anonfun$12.apply(Trees.scala:
> 928)
>         at
> scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1046)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:927)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $OuterPathTransformer.transform(ExplicitOuter.scala:132)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anon$0.transform(ExplicitOuter.scala:311)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anonfun$7.apply(ExplicitOuter.scala:357)
>         at
> scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer$
> $anonfun$7.apply(ExplicitOuter.scala:357)
>         at
> scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:38)
>         at
> scala.tools.nsc.transform.ExplicitOuter
> $ExplicitOuterTransformer.transform(ExplicitOuter.scala:356)
>         at
> scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:1041)
>         at
> scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:22)
>         at
> scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:210)
>         at
> scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:199)
>         at
> scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:199)
>         at scala.Iterator$class.foreach(Iterator.scala:285)
>         at
> scala.collection.mutable.ListBuffer$$anon$0.foreach
> (ListBuffer.scala:216)
>         at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:199)
>         at scala.tools.nsc.Global$Run.compileSources(Global.scala:429)
>         at scala.tools.nsc.Global$Run.compile(Global.scala:487)
>         at scala.tools.nsc.Main$.process(Main.scala:60)
>         at scala.tools.nsc.Main$.main(Main.scala:82)
>         at scala.tools.nsc.Main.main(Main.scala)

Reply | Threaded
Open this post in threaded view
|

Re: self types

Bogdan Dumitriu
Hi Sean,

Thanks for your reply. Your workaround did indeed help, though it took
some more reading on my part for understanding what implicit
definitions were all about.

I'm glad I could help with the example.

Bogdan.

On Monday 15 May 2006 18:18, Sean McDirmid wrote:

> Hi Bogdan,
>
> Its definitely a bug we know about although I don't know how long it
> will take to fix. Thanks for your example, I've added it to the bug
> report as mine was way too big to fit in one page. As a temporary
> workaround, I'm currently using implicit coercions and an explicit
> self def. E.g.,
>
> trait NodeIntf {
>    def self : Node;
>    def connectWith(node : Node): Edge;
> }
> implicit def convert(node : NodeIntf) = node.self;
>
> Then ...
>
> class ConcreteDirectedGraph extends DirectedGraph {
>    type Node = NodeImpl0;
>
>    class NodeImpl0 extends NodeImpl {
>      def self = this;
>    }
>    // instantiate NodeImpl0 instead of NodeImpl.
>
>
>
> Should do the trick in most cases. Of course, this just a temporary
> fix until requires works again.
>
> Thanks again for your bug report.
>
> Sean
Reply | Threaded
Open this post in threaded view
|

Re: self types

sean.mcdirmid
Hi Bogdan,

This bug has been fixed and will be a part of the next compiler  
release (due within the week I think).

Thanks!

Sean

On May 15, 2006, at 9:18 PM, Bogdan Dumitriu wrote:

> Hi Sean,
>
> Thanks for your reply. Your workaround did indeed help, though it took
> some more reading on my part for understanding what implicit
> definitions were all about.
>
> I'm glad I could help with the example.
>
> Bogdan.
>
> On Monday 15 May 2006 18:18, Sean McDirmid wrote:
>> Hi Bogdan,
>>
>> Its definitely a bug we know about although I don't know how long it
>> will take to fix. Thanks for your example, I've added it to the bug
>> report as mine was way too big to fit in one page. As a temporary
>> workaround, I'm currently using implicit coercions and an explicit
>> self def. E.g.,
>>
>> trait NodeIntf {
>>    def self : Node;
>>    def connectWith(node : Node): Edge;
>> }
>> implicit def convert(node : NodeIntf) = node.self;
>>
>> Then ...
>>
>> class ConcreteDirectedGraph extends DirectedGraph {
>>    type Node = NodeImpl0;
>>
>>    class NodeImpl0 extends NodeImpl {
>>      def self = this;
>>    }
>>    // instantiate NodeImpl0 instead of NodeImpl.
>>
>>
>>
>> Should do the trick in most cases. Of course, this just a temporary
>> fix until requires works again.
>>
>> Thanks again for your bug report.
>>
>> Sean