mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
f54e45b77e
commit
32fa475316
@ -204,7 +204,7 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F
|
||||
all_fn_root_names << k
|
||||
continue
|
||||
}
|
||||
if mfn.receiver.typ != ast.void_type && mfn.receiver.typ.has_flag(.generic) {
|
||||
if mfn.receiver.typ != ast.void_type && mfn.generic_names.len > 0 {
|
||||
// generic methods may be used in cgen after specialisation :-|
|
||||
// TODO: move generic method specialisation from cgen to before markused
|
||||
all_fn_root_names << k
|
||||
|
1
vlib/v/tests/skip_unused/nested_generics_method.run.out
Normal file
1
vlib/v/tests/skip_unused/nested_generics_method.run.out
Normal file
@ -0,0 +1 @@
|
||||
OK!!
|
@ -0,0 +1 @@
|
||||
OK!!
|
54
vlib/v/tests/skip_unused/nested_generics_method.vv
Normal file
54
vlib/v/tests/skip_unused/nested_generics_method.vv
Normal file
@ -0,0 +1,54 @@
|
||||
struct Calc<S> {
|
||||
mut:
|
||||
typ S
|
||||
}
|
||||
|
||||
struct TypeA {}
|
||||
|
||||
struct TypeB {}
|
||||
|
||||
fn (mut c Calc<S>) next<T>(input T) f64 {
|
||||
$if S is TypeA || S is TypeB {
|
||||
return c.typ.next(input)
|
||||
} $else {
|
||||
return 99.0
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut t TypeA) next<T>(input T) f64 {
|
||||
return 10
|
||||
}
|
||||
|
||||
fn (mut t TypeB) next<T>(input T) f64 {
|
||||
return 11
|
||||
}
|
||||
|
||||
fn new<S>() Calc<S> {
|
||||
$if S is TypeA {
|
||||
return Calc<TypeA>{
|
||||
typ: TypeA{}
|
||||
}
|
||||
} $else $if S is TypeB {
|
||||
return Calc<TypeB>{
|
||||
typ: TypeB{}
|
||||
}
|
||||
} $else {
|
||||
panic('unknown type $S.name')
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
{
|
||||
mut c := Calc<TypeA>{
|
||||
typ: TypeA{}
|
||||
}
|
||||
assert c.next(100) == 10.0
|
||||
}
|
||||
{
|
||||
mut c := Calc<TypeB>{
|
||||
typ: TypeB{}
|
||||
}
|
||||
assert c.next(100) == 11.0
|
||||
}
|
||||
println('OK!!')
|
||||
}
|
Loading…
Reference in New Issue
Block a user