Scala path dependent return type from parameter

Posted by Rich Oliver on Stack Overflow See other posts from Stack Overflow or by Rich Oliver
Published on 2012-06-19T22:29:41Z Indexed on 2012/06/20 15:16 UTC
Read the original article Hit count: 195

In the following code using 2.10.0M3 in Eclipse plugin 2.1.0 for 2.10M3. I'm using the default setting which is targeting JVM 1.5

class GeomBase[T <: DTypes] {          
  abstract class NewObjs {
    def newHex(gridR: GridBase, coodI: Cood): gridR.HexRT          
  }

  class GridBase {
    selfGrid =>
      type HexRT = HexG with T#HexTr

    def uniformRect (init: NewObjs) {
      val hexCood = Cood(2 ,2)
      val hex: HexRT = init.newHex(selfGrid, hexCood)//  won't compile
    }
  }
}

Error message:

Description Resource Path Location Type type mismatch;
  found: GeomBase.this.GridBase#HexG with T#HexTr
  required: GridBase.this.HexRT (which expands to) GridBase.this.HexG with T#HexTr GeomBase.scala   

Why does the compiler think the method returns the type projection GridBase#HexG when it should be this specific instance of GridBase?

Edit transferred to a simpler code class in responce to comments now getting a different error message.

package rStrat
class TestClass {
  abstract class NewObjs {
    def newHex(gridR: GridBase): gridR.HexG
  }     
  class GridBase {
    selfGrid =>         

    def uniformRect (init: NewObjs) {
      val hex: HexG = init.newHex(this) //error here                        
    }       

    class HexG {
      val test12 = 5                 
    }
  }
}

.

Error line 11:Description   Resource    Path    Location    Type
type mismatch;  found   : gridR.HexG  required: GridBase.this.HexG
possible cause: missing arguments for method or constructor TestClass.scala /SStrat/src/rStrat  line 11 Scala Problem

Update I've switched to 2.10.0M4 and updated the plug-in to the M4 version on a fresh version of Eclipse and switched to JVM 1.6 (and 1.7) but the problems are unchanged.

© Stack Overflow or respective owner

Related posts about scala

Related posts about parameters