Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When JS, operations on pointer casted from ref object raises Runtime-Errors #23850

Open
litlighilit opened this issue Jul 17, 2024 · 0 comments

Comments

@litlighilit
Copy link
Contributor

litlighilit commented Jul 17, 2024

Description

There are two kinds of errors I've found:

Given here are two variables:

type O = ref object
var p1, p2: O
  1. TypeError: Cannot read properties of null (reading 'undefined')
func `+`(a: pointer): int = cast[int](a)
discard +cast[pointer](p1)
  1. SyntaxError: Unexpected token '=='
discard cast[pointer](p1) == cast[pointer](p2)

(here an odd == token is generated with no operands)
And I know p1 == p2 just works and is preferred.

Nim Version

Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-06-27
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 828cd58
active boot switches: -d:release

Current Output

    result_520093703 = a_p0[a_p0_Idx];
                           ^
TypeError: Cannot read properties of null (reading 'undefined')
(( ==  && p1_520093699[0] == p2_520093700[0]));
   ^^
SyntaxError: Unexpected token '=='

Expected Output

(runs without error)

Possible Solution

No response

Additional Information

For the second, if:

func `+`(a, b: pointer): int = cast[int](a) + cast[int](a)
discard cast[pointer](p1) + cast[pointer](p2)

Then error is:

    result_520093707 = addInt(a_p0[a_p0_Idx], a_p0[a_p0_Idx]);
                                                           ^

TypeError: Cannot read properties of null (reading 'null')

donno why the two operands are just the same.

@litlighilit litlighilit changed the title Think about the title, twice. When JS, operations on pointer casted from ref object raises Runtime-Errors Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants