【问题标题】:Scala path dependent return type from parameterScala 路径相关的参数返回类型
【发布时间】:2012-06-22 01:11:34
【问题描述】:

在下面的代码中使用 Eclipse 插件 2.1.0 中的 2.10.0M3 为 2.10M3。我正在使用针对 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
    }
  }
}

错误信息:

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   

为什么编译器认为该方法返回类型投影 GridBase#HexG 而应该是 GridBase 的这个特定实例?

编辑转移到更简单的代码类以响应 cmets 现在收到不同的错误消息。

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

更新我已经切换到 2.10.0M4 并将插件更新到新版本的 Eclipse 上的 M4 版本并切换到 JVM 1.6(和 1.7),但问题没有改变。

【问题讨论】:

  • 能否请您添加一个产生错误消息的工作代码示例?
  • 您应该粘贴带有错误的源代码行以及指向错误确切位置的箭头,这些箭头也会显示出来。
  • @RichOliver 该错误下方仍应有几行。带有错误本身的代码行,以及在其下方的带有单个 ^ 字符的行,指向错误。

标签: scala parameters path-dependent-type


【解决方案1】:

现在从 2.10.0M7 开始有效。该错误已修复。

val hex: HexRT = init.newHex(selfGrid, hexCood) //now compiles and runs correctly

【讨论】:

    【解决方案2】:

    记录为SI-5958 - 将其替换为依赖方法类型

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      • 2015-12-14
      • 2019-02-17
      • 2017-03-30
      相关资源
      最近更新 更多