Skip to content

Commit

Permalink
Fix optional test to be functional (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones authored Nov 21, 2024
1 parent 4b73ba3 commit ff1302f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions interpreter/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func (p *planner) planCreateList(expr ast.Expr) (Interpretable, error) {
id: expr.ID(),
elems: elems,
optionals: optionals,
hasOptionals: len(optionals) != 0,
hasOptionals: len(optionalIndices) != 0,
adapter: p.adapter,
}, nil
}
Expand All @@ -518,6 +518,7 @@ func (p *planner) planCreateMap(expr ast.Expr) (Interpretable, error) {
optionals := make([]bool, len(entries))
keys := make([]Interpretable, len(entries))
vals := make([]Interpretable, len(entries))
hasOptionals := false
for i, e := range entries {
entry := e.AsMapEntry()
keyVal, err := p.Plan(entry.Key())
Expand All @@ -532,13 +533,14 @@ func (p *planner) planCreateMap(expr ast.Expr) (Interpretable, error) {
}
vals[i] = valVal
optionals[i] = entry.IsOptional()
hasOptionals = hasOptionals || entry.IsOptional()
}
return &evalMap{
id: expr.ID(),
keys: keys,
vals: vals,
optionals: optionals,
hasOptionals: len(optionals) != 0,
hasOptionals: hasOptionals,
adapter: p.adapter,
}, nil
}
Expand All @@ -554,6 +556,7 @@ func (p *planner) planCreateStruct(expr ast.Expr) (Interpretable, error) {
optionals := make([]bool, len(objFields))
fields := make([]string, len(objFields))
vals := make([]Interpretable, len(objFields))
hasOptionals := false
for i, f := range objFields {
field := f.AsStructField()
fields[i] = field.Name()
Expand All @@ -563,14 +566,15 @@ func (p *planner) planCreateStruct(expr ast.Expr) (Interpretable, error) {
}
vals[i] = val
optionals[i] = field.IsOptional()
hasOptionals = hasOptionals || field.IsOptional()
}
return &evalObj{
id: expr.ID(),
typeName: typeName,
fields: fields,
vals: vals,
optionals: optionals,
hasOptionals: len(optionals) != 0,
hasOptionals: hasOptionals,
provider: p.provider,
}, nil
}
Expand Down

0 comments on commit ff1302f

Please sign in to comment.