Skip to content

Commit

Permalink
sema: improve array size error
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Jun 15, 2024
1 parent 0664faa commit dc2db5b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions std/jule/build/log.jule
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ enum LogMsg: str {
MissingArgs: `missing arguments to call @`,
InheritedNonTrait: `trait @ cannot implement @, type should be trait`,
IncompatibleInherit: "trait @ inherits trait @, but same identifiers implemented different;\n @\n @",
ArraySizeOverflow: "array with size @ overflows limit (@) of the system",

// Suggestions.
ExpectedIdentifier: `write an identifier because identifier expected`,
Expand Down
11 changes: 11 additions & 0 deletions std/jule/sema/eval.jule
Original file line number Diff line number Diff line change
Expand Up @@ -4399,4 +4399,15 @@ fn pushSubIdentFromExpr(mut expr: ExprData, mut &t: &SubIdentTypeDecl): bool {
ret false
}
ret true
}

fn constoa(&c: &Const): str {
match {
| c.IsI64():
ret conv::FmtInt(c.ReadI64(), 10)
| c.IsU64():
ret conv::FmtUint(c.ReadU64(), 10)
|:
ret ""
}
}
10 changes: 7 additions & 3 deletions std/jule/sema/type.jule
Original file line number Diff line number Diff line change
Expand Up @@ -1277,9 +1277,13 @@ impl typeChecker {
if n < 0 {
self.pushErr(decl.Elem.Token, LogMsg.ArraySizeIsNeg)
ret nil
} else if types::BitSize != 64 && f64(n) > types::Max(PrimKind.Int) {
self.pushErr(decl.Size.Token, LogMsg.OverflowLimits)
ret nil
} else {
let max = types::MaxI(PrimKind.Int)
if types::BitSize != 64 && i64(n) > max {
self.pushErr(decl.Size.Token, LogMsg.ArraySizeOverflow,
constoa(size.Constant), conv::FmtInt(max, 10))
ret nil
}
}
}

Expand Down

0 comments on commit dc2db5b

Please sign in to comment.