table: fix interface embedding with interface parameter (#10567)
parent
e648578f79
commit
e9de30373f
|
@ -116,6 +116,11 @@ pub mut:
|
|||
pub fn (f Fn) new_method_with_receiver_type(new_type Type) Fn {
|
||||
mut new_method := f
|
||||
new_method.params = f.params.clone()
|
||||
for i in 1 .. new_method.params.len {
|
||||
if new_method.params[i].typ == new_method.params[0].typ {
|
||||
new_method.params[i].typ = new_type
|
||||
}
|
||||
}
|
||||
new_method.params[0].typ = new_type
|
||||
return new_method
|
||||
}
|
||||
|
@ -123,6 +128,11 @@ pub fn (f Fn) new_method_with_receiver_type(new_type Type) Fn {
|
|||
pub fn (f FnDecl) new_method_with_receiver_type(new_type Type) FnDecl {
|
||||
mut new_method := f
|
||||
new_method.params = f.params.clone()
|
||||
for i in 1 .. new_method.params.len {
|
||||
if new_method.params[i].typ == new_method.params[0].typ {
|
||||
new_method.params[i].typ = new_type
|
||||
}
|
||||
}
|
||||
new_method.params[0].typ = new_type
|
||||
return new_method
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
interface Eq {
|
||||
eq(other Eq) bool
|
||||
}
|
||||
|
||||
interface Ord {
|
||||
Eq
|
||||
lt(other Ord) bool
|
||||
}
|
||||
|
||||
// implement Ord for Int
|
||||
struct Int {
|
||||
value int
|
||||
}
|
||||
|
||||
fn (i Int) eq(other Ord) bool {
|
||||
if other is Int {
|
||||
return i.value == other.value
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fn (i Int) lt(other Ord) bool {
|
||||
if other is Int {
|
||||
return i.value < other.value
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fn compare(x Ord, y Ord) {
|
||||
println(x.eq(y))
|
||||
assert !x.eq(y)
|
||||
println(x.lt(y))
|
||||
assert x.lt(y)
|
||||
}
|
||||
|
||||
fn test_interface_embedding_with_interface_para() {
|
||||
compare(Int{1}, Int{2})
|
||||
}
|
Loading…
Reference in New Issue