Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala path dependent return type from parameter

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.

like image 453
Rich Oliver Avatar asked Jun 19 '12 22:06

Rich Oliver


2 Answers

logged as SI-5958 - substitute this in dependent method type

like image 157
Adriaan Moors Avatar answered Nov 12 '22 00:11

Adriaan Moors


This now works as of 2.10.0M7. The bug has been fixed.

val hex: HexRT = init.newHex(selfGrid, hexCood) //now compiles and runs correctly
like image 22
Rich Oliver Avatar answered Nov 12 '22 01:11

Rich Oliver