Skip to content

Commit

Permalink
sema: caught variadic reference parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Jun 29, 2024
1 parent fdf26bb commit 61a0b5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions std/internal/fmt/format.jule
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ fn FmtByDefault(mut &buf: str, &arg: any) {
}
}

fn applyFmtByDefault(mut &buf: str, mut &j: int, &args: ...any) {
fn applyFmtByDefault(mut &buf: str, mut &j: int, args: ...any) {
let arg = args[j]
j++
FmtByDefault(buf, arg)
}

// Returns result of formatting.
// Parameter j is the position of argument list.
fn applyFmt(mut &fmt: []byte, mut &buf: str, mut &j: int, &args: ...any) {
fn applyFmt(mut &fmt: []byte, mut &buf: str, mut &j: int, args: ...any) {
// {}
if len(fmt) == 2 {
applyFmtByDefault(buf, j, args...)
Expand Down
1 change: 1 addition & 0 deletions std/jule/build/log.jule
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ enum LogMsg: str {
VariadicParamNotLast: `variadic parameter can only be last parameter`,
VariadicWithNonVariadicable: `type @ is not variadicable`,
MoreArgsWithVariadiced: `variadic argument can't use with more argument`,
VariadicReference: `variadic storage cannot be reference`,
TypeNotSupportsCasting: `type @ not supports casting`,
TypeNotSupportsCastingTo: `type @ not supports casting to type @`,
UseAtContent: `use declaration must be start of source code`,
Expand Down
12 changes: 12 additions & 0 deletions std/jule/sema/sema.jule
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,17 @@ impl Sema {
ret
}

fn checkFnVariadicParam(mut &self, mut &f: &Fn): bool {
if len(f.Params) == 0 {
ret false
}
let mut param = f.Params[len(f.Params)-1]
if param.Variadic && param.Reference {
self.pushErr(param.Token, LogMsg.VariadicReference)
}
ret true
}

// Checks generics, parameters and return type.
// Not checks scope, and other things.
fn checkFnDeclPrototype(mut &self, mut &f: &Fn) {
Expand All @@ -1540,6 +1551,7 @@ impl Sema {
| !self.checkDeclGenerics(f.Generics):
| !self.checkFnDeclParamsDup(f):
| !self.checkFnDeclResultDup(f):
| !self.checkFnVariadicParam(f):
}
}

Expand Down

0 comments on commit 61a0b5a

Please sign in to comment.