markused: fix `-skip-unused` on programs with generic methods (fix #12306)

pull/12314/head
Delyan Angelov 2021-10-27 17:07:10 +03:00
parent 462d097bf5
commit 159a9c3070
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 39 additions and 0 deletions

View File

@ -203,6 +203,12 @@ 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) {
// generic methods may be used in cgen after specialisation :-|
// TODO: move generic method specialisation from cgen to before markused
all_fn_root_names << k
continue
}
// testing framework:
if pref.is_test {
if k.starts_with('test_') || k.contains('.test_') {

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,31 @@
interface Something {
i int
}
struct Some {
i int
}
struct App<M> {
f M
}
fn (mut self App<M>) next<M, T>(input T) f64 {
$if M is Something {
return 0
} $else {
panic('${typeof(M.typ).name} is not supported')
return 1
}
return 1
}
fn main() {
mut app := App<Some>{
f: Some{
i: 10
}
}
assert app.next(1) == 0
println(app.next(1))
}