Skip to content

Commit d927fe4

Browse files
committed
struct-function: cleanup analyserl, added test-case
1 parent 346de8d commit d927fe4

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

analyser/module_analyser_function.c2

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,17 @@ fn void Analyser.analyseFunction(Analyser* ma, FunctionDecl* fd) {
130130

131131
bool is_typefn = false;
132132
if (num_params && fd.hasPrefix()) {
133-
// check if SF if first arg is (const) Struct*
133+
// check if SF if first arg is (const) Struct* or (const) Struct
134134
// Note: use TypeRef, since it's faster to check
135135
const Ref* prefix = fd.getPrefix();
136136
const Decl* pd = prefix.decl;
137137
assert(pd);
138138
QualType prefixType = pd.getType();
139139

140-
bool is_non_static = true;
141140
TypeRef* ref = params[0].getTypeRef();
142141
const Ref* param_ref = ref.getUser();
143-
if (0 && pd.isStructType()) {
144-
// Note: for struct/union it can only be a pointer to that Type.
145-
is_non_static = ref.isPointerTo(prefixType.getIndex());
146-
} else { // enum type
147-
// Note: for enum types it can be the Type or a pointer to that type
148-
is_non_static = ((param_ref && param_ref.decl == prefix.decl) || ref.isPointerTo(prefixType.getIndex()));
149-
}
150-
142+
// Note: for enum types it can be the Type or a pointer to that type
143+
bool is_non_static = ((param_ref && param_ref.decl == prefix.decl) || ref.isPointerTo(prefixType.getIndex()));
151144
if (is_non_static) {
152145
fd.setCallKind(CallKind.TypeFunc);
153146
is_typefn = true;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @warnings{no-unused}
2+
module test;
3+
4+
type Foo struct {
5+
i32 a;
6+
}
7+
8+
fn void Foo.init(Foo* f, i32 a) {
9+
f.a = a;
10+
}
11+
12+
fn i32 Foo.getA(const Foo f) {
13+
return f.a;
14+
}
15+
16+
type Bar struct {
17+
Foo f;
18+
}
19+
20+
fn void Bar.init(Bar* b, i32 a) {
21+
b.f.init(a);
22+
}
23+
24+
fn Foo Bar.getF(Bar b) {
25+
return b.f;
26+
}
27+
28+
fn i32 test1() {
29+
Bar b.init(20);
30+
return b.getF().getA();
31+
}
32+
33+

0 commit comments

Comments
 (0)