Skip to content

Commit

Permalink
feat: add nil predeclared identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
shenyih0ng committed Apr 17, 2024
1 parent 7850fbd commit 25ffe39
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/go-slang/lib/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,17 @@ function evaluateRelationalOp(
left: any,
right: any
): Result<boolean, InvalidOperationError> {
if (!isSameType(left, right)) {
const hasNil = left === undefined || right === undefined

if (!isSameType(left, right) && !hasNil) {
return Result.fail(
new InvalidOperationError(
`${left} ${operator} ${right} (mismatched types ${_typeof(left)} and ${_typeof(right)})`
)
)
}

if (_typeof(left) === 'heapObj') {
if (_typeof(left) === 'heapObj' && !hasNil) {
if (operator !== '==' && operator !== '!=') {
return Result.fail(
new InvalidOperationError(
Expand Down
1 change: 1 addition & 0 deletions src/go-slang/lib/predeclared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface PredeclaredFunc {
export const PREDECLARED_IDENTIFIERS: { [key: string]: any } = {
true: true,
false: false,
nil: undefined,
'sync.WaitGroup': NewType.WaitGroup,
'sync.Mutex': NewType.Mutex
}
Expand Down

0 comments on commit 25ffe39

Please sign in to comment.