Skip to content

Commit

Permalink
compiler: generic compile-time panic logs use location of relevant fu…
Browse files Browse the repository at this point in the history
…nction call
  • Loading branch information
mertcandav committed Mar 19, 2024
1 parent 066e317 commit 2431c1d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion std/jule/sema/eval.jule
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,7 @@ impl Eval {

if f.generics.len > 0 && is_unique_ins {
// Check generic function instance instantly.
self.s.check_fn_ins(f)
self.s.check_fn_ins_caller(f, unsafe { (&Token)(&fc.token) })
}
}

Expand Down
11 changes: 6 additions & 5 deletions std/jule/sema/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ struct ScopeGoto {

// Scope checker.
struct ScopeChecker {
called_from: &Token
s: &Sema
owner: &FnIns // See developer reference (1).
parent: &ScopeChecker
Expand Down Expand Up @@ -1531,7 +1532,7 @@ impl ScopeChecker {
ret def
}

fn check_comptime_panic(mut self, &s: &Scope, error_token: Token) {
fn check_comptime_panic(mut self, &s: &Scope) {
if s.stmts.len != 1 {
ret
}
Expand All @@ -1547,7 +1548,7 @@ impl ScopeChecker {
| &Const:
let c = (&Const)(m.expr)
if c.is_str() {
self.s.push_err(error_token, LogMsg.ComptimePanic, c.read_str())
self.s.push_err(*self.called_from, LogMsg.ComptimePanic, c.read_str())
}
}
}
Expand All @@ -1558,16 +1559,16 @@ impl ScopeChecker {
// Type kind is generic.
// Match cases by kind.
if tm.expr.kind.generic {
for (i, mut c) in tm.cases {
for (_, mut c) in tm.cases {
if c.scope != nil {
tm.cases = nil
tm.default = c
self.check_comptime_panic(c.scope, m.cases[i].token)
self.check_comptime_panic(c.scope)
goto push
}
}
if tm.default != nil {
self.check_comptime_panic(tm.default.scope, m.default.token)
self.check_comptime_panic(tm.default.scope)
}
tm.cases = nil
}
Expand Down
7 changes: 6 additions & 1 deletion std/jule/sema/sema.jule
Original file line number Diff line number Diff line change
Expand Up @@ -2364,7 +2364,7 @@ impl Sema {
}
}

fn check_fn_ins(mut &self, mut &f: &FnIns) {
fn check_fn_ins_caller(mut &self, mut &f: &FnIns, mut caller: &Token) {
if f.decl.cpp_linked {
ret
}
Expand All @@ -2377,6 +2377,7 @@ impl Sema {
}

let mut sc = new_scope_checker(f.decl.sema, f)
sc.called_from = caller
self.check_fn_ins_sc(f, sc)

if f.decl.sema != self {
Expand All @@ -2385,6 +2386,10 @@ impl Sema {
}
}

fn check_fn_ins(mut &self, mut &f: &FnIns) {
self.check_fn_ins_caller(f, nil)
}

fn check_type_fn(mut &self, mut &f: &Fn) {
if f.cpp_linked {
ret
Expand Down

0 comments on commit 2431c1d

Please sign in to comment.