Skip to content

Commit

Permalink
sema: add operator overloading support for genericed structures
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 28, 2024
1 parent 6fdd5a8 commit ec223aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
35 changes: 15 additions & 20 deletions std/jule/sema/sema.jule
Original file line number Diff line number Diff line change
Expand Up @@ -1409,9 +1409,7 @@ impl Sema {
ret
}

fn check_fn_decl_types(mut &self, mut &f: &Fn): (ok: bool) {
ok = true

fn check_fn_decl_types(mut &self, mut &f: &Fn) {
let mut generics = f.generics
if f.owner != nil && f.owner.generics.len != 0 {
generics = append(generics, f.owner.generics...)
Expand All @@ -1420,26 +1418,22 @@ impl Sema {
for (_, mut p) in f.params {
if !p.is_self() {
let mut kind = self.build_non_generic_type_kind(p.kind.decl, generics)
ok = ok && kind != nil
p.kind.kind = kind
}
}

if !f.is_void() {
let mut kind = self.build_non_generic_type_kind(f.result.kind.decl, generics)
ok = ok && kind != nil
f.result.kind.kind = kind
}

ret ok
}

// Checks generics, parameters and return type.
// Not checks scope, and other things.
fn check_fn_decl_prototype(mut &self, mut &f: &Fn): (ok: bool) {
fn check_fn_decl_prototype(mut &self, mut &f: &Fn) {
if f.exceptional && f.cpp_linked {
self.push_err(f.token, LogMsg.CDefineExceptional)
ret false
ret
}

if f.exceptional {
Expand All @@ -1451,12 +1445,12 @@ impl Sema {
}

match {
| !self.check_decl_generics(f.generics): ret false
| !self.check_fn_decl_params_dup(f): ret false
| !self.check_fn_decl_result_dup(f): ret false
| !self.check_fn_decl_types(f): ret false
|: ret true
| !self.check_decl_generics(f.generics): ret
| !self.check_fn_decl_params_dup(f): ret
| !self.check_fn_decl_result_dup(f): ret
}

self.check_fn_decl_types(f)
}

fn check_trait_decl_method(mut &self, mut &f: &Fn) {
Expand Down Expand Up @@ -1806,7 +1800,8 @@ impl Sema {

fn check_struct_decl_methods(mut &self, mut &s: &Struct): (ok: bool) {
for (_, mut m) in s.methods {
if !self.check_fn_decl_types(m) {
self.check_fn_decl_types(m)
if self.errors.len > 0 {
ret false
}
match m.ident {
Expand Down Expand Up @@ -1883,10 +1878,10 @@ impl Sema {

s.sema = self
match {
| !self.check_decl_generics(s.generics): ret
| !self.check_struct_fields(s): ret
| !self.check_struct_decl_methods(s): ret
| !self.check_struct_impls(s): ret
| !self.check_decl_generics(s.generics):
| !self.check_struct_fields(s):
| !self.check_struct_decl_methods(s):
| !self.check_struct_impls(s):
}
}

Expand Down Expand Up @@ -1915,7 +1910,7 @@ impl Sema {
self.check_directives(f.directives, f)

f.sema = self
_ = self.check_fn_decl_prototype(f)
self.check_fn_decl_prototype(f)
}

// Checks current package file's function declarations.
Expand Down
5 changes: 1 addition & 4 deletions std/jule/sema/type.jule
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ impl TypeChecker {
}

if ins.generics.len > 0 {
self.s.check_struct_ins_operators(ins)
self.s.check_struct_ins(ins)
}

Expand Down Expand Up @@ -1187,19 +1188,16 @@ impl TypeChecker {
match {
| elem == nil:
ret nil

| elem.strct() != nil:
let s = elem.strct()
if s.decl != nil && s.decl.cpp_linked {
self.push_err(self.error_token, LogMsg.CppLinkedStructForRef)
ret nil
}

| elem.arr() != nil && elem.arr().auto:
self.push_err(self.error_token, LogMsg.ArrayAutoSized)
ret nil
}

ret &Sptr{
elem: elem,
}
Expand Down Expand Up @@ -1303,7 +1301,6 @@ impl TypeChecker {
match {
| elem == nil:
ret nil

| elem.arr() != nil && elem.arr().auto:
self.push_err(decl.elem.token, LogMsg.ArrayAutoSized)
ret nil
Expand Down

0 comments on commit ec223aa

Please sign in to comment.