Skip to content

Commit

Permalink
sema: fix lvalue analysis of indexing epxressions
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Aug 3, 2024
1 parent 56e5b94 commit cd39dd2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 7 additions & 2 deletions std/jule/sema/eval.jule
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ impl Eval {

fn indexingPtr(mut self, mut &d: &Data, mut &index: &Data, &i: &IndexingExpr) {
self.checkIntegerIndexingByData(index, i.Token)
d.Lvalue = true

let mut ptr = d.Kind.Ptr()
match {
Expand All @@ -938,6 +939,7 @@ impl Eval {
let mut arr = d.Kind.Arr()
d.Kind = arr.Elem
self.checkIntegerIndexingByData(index, i.Token)
d.Lvalue = true
if index.IsConst() && index.Constant.AsF64() >= f64(arr.N) {
self.pushErr(i.Token, LogMsg.OverflowLimits)
}
Expand All @@ -947,6 +949,7 @@ impl Eval {
let mut slc = d.Kind.Slc()
d.Kind = slc.Elem
self.checkIntegerIndexingByData(index, i.Token)
d.Lvalue = true

// Check compile-time bounds.
if !index.IsConst() {
Expand All @@ -966,6 +969,7 @@ impl Eval {
}

fn indexingMap(mut self, mut &d: &Data, mut &index: &Data, mut &i: &IndexingExpr) {
d.Lvalue = true
if index == nil {
ret
}
Expand All @@ -983,6 +987,7 @@ impl Eval {
fn indexingStr(mut self, mut &d: &Data, mut &index: &Data, &i: &IndexingExpr) {
d.Kind = primU8 // Byte
d.Mutable = false
d.Lvalue = true

if index == nil {
ret
Expand Down Expand Up @@ -1241,7 +1246,7 @@ impl Eval {
ret d
}

let mut old_d = *d
let mut oldData = *d

let mut index = self.evalExpr(i.Index)
if index == nil {
Expand All @@ -1262,7 +1267,7 @@ impl Eval {
} else {
d.Model = &IndexingExprModel{
Token: i.Token,
Expr: new(Data, old_d),
Expr: new(Data, oldData),
Index: index,
}
}
Expand Down
7 changes: 3 additions & 4 deletions std/jule/sema/type.jule
Original file line number Diff line number Diff line change
Expand Up @@ -1758,11 +1758,10 @@ fn hasDirective(mut &directives: []&ast::Directive, tag: str): bool {
}

fn canGetPtr(mut &d: &Data): bool {
if !d.Lvalue || d.IsConst() {
ret false
}
match {
| d.Kind.Fn() != nil || d.Kind.Enum() != nil:
| !d.Lvalue | d.IsConst():
ret false
| d.Kind.Fn() != nil | d.Kind.Enum() != nil:
ret false
|:
ret true
Expand Down

0 comments on commit cd39dd2

Please sign in to comment.