【发布时间】:2020-05-24 20:33:03
【问题描述】:
我有以下设置,我正在尝试通过代码的编译类型检查,最好进行最少的修改,因为代码是由工具生成的,而不是手动生成的。
我认为问题是我需要为M_TEST_COLL 中的T_MAX_LATTICE[T] 或T_IntegerMaxLattice 提出一个更好的定义。
代码有点大,所以我不能在这里发布整个代码,但我把 repo URL 放在了底部。我正在努力可视化类型层次结构。
我知道这个问题太笼统了,但我正在寻找的是能够在不使用 uncheck cast(或asInstanceOf)的情况下编译代码
type T_MAX_LATTICE[T] = T;
trait C_TEST_COLL[T_Result, T_T] extends C_TYPE[T_Result] with C_TINY[T_Result] {
type T_IntegerMaxLattice;
val t_IntegerMaxLattice : C_TYPE[T_IntegerMaxLattice] with C_MAX_LATTICE[T_IntegerMaxLattice,T_Integer];
type T_Integers;
val t_Integers : C_TYPE[T_Integers]with C_SET[T_Integers,T_Integer];
class M_TEST_COLL[T_T](name : String,val t_T : C_TYPE[T_T] with C_TINY[T_T])
extends Module(name)
with C_TEST_COLL[T_T,T_T]
{
val t_Result : this.type = this;
val t_IntegerMaxLattice = new M_MAX_LATTICE[T_Integer]("IntegerMaxLattice",t_Integer,0);
type T_IntegerMaxLattice = T_MAX_LATTICE[T_Integer];
我得到的错误:
Error:Error:line (42)type mismatch;
found : M_MAX_LATTICE[basic_implicit.T_Integer]
(which expands to) M_MAX_LATTICE[Int]
required: C_TYPE[M_TEST_COLL.this.T_IntegerMaxLattice] with C_MAX_LATTICE[M_TEST_COLL.this.T_IntegerMaxLattice,basic_implicit.T_Integer]
(which expands to) C_TYPE[Int] with C_MAX_LATTICE[Int,Int]
val t_IntegerMaxLattice = new M_MAX_LATTICE[T_Integer]("IntegerMaxLattice",t_Integer,0);
【问题讨论】:
-
我建议阅读有关 Scala code style(例如避免无用的
;)和naming conventions(例如蛇大写类型名称...)的文档