nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.22k stars 1.46k forks source link

`int64/int64` not compile for JS, but for C. #23746

Open litlighilit opened 1 week ago

litlighilit commented 1 week ago

Description

the following compiles for C backend but not JS:

echo 1'i64 / 2'i64

or

echo 1.int64 / 2.int64

Nim Version

from 1.6.14, 2.0.6 to 2.1.1

Current Output

Error: type mismatch
Expression: 1'i64 / 2'i64
  [1] 1'i64: int64
  [2] 2'i64: int64

Expected one of (first mismatch at [position]):
[1] proc `/`(x, y: float): float
[1] proc `/`(x, y: float32): float32
[1] proc `/`(x, y: int): float

Expected Output

0.5

Possible Solution

No response

Additional Information

No response

litlighilit commented 1 week ago

!nim js

echo 1'i64 / 2'i64
github-actions[bot] commented 1 week ago
:penguin: Linux bisect by @litlighilit (contributor)
devel :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-06-20T15:47:26
  • Finished 2024-06-20T15:47:26
  • Duration now

AST

```nim ```
stable :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-06-20T15:47:27
  • Finished 2024-06-20T15:47:27
  • Duration now

AST

```nim ```
2.0.4 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-06-20T15:47:30
  • Finished 2024-06-20T15:47:30
  • Duration now

AST

```nim ```
2.0.0 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-06-20T15:47:33
  • Finished 2024-06-20T15:47:33
  • Duration now

AST

```nim ```
1.6.20 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-06-20T15:47:36
  • Finished 2024-06-20T15:47:36
  • Duration

AST

```nim ```
1.4.8 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-06-20T15:47:39
  • Finished 2024-06-20T15:47:39
  • Duration now

AST

```nim ```
1.2.18 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-06-20T15:47:41
  • Finished 2024-06-20T15:47:41
  • Duration now

AST

```nim ```
1.0.10 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-06-20T15:47:44
  • Finished 2024-06-20T15:47:44
  • Duration now

AST

```nim ```
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.3
  • Created 2024-06-20T15:40:49Z
  • Comments 1
  • Commands nim js -d:nodejs -d:nimExperimentalAsyncjsThen -d:nimExperimentalJsfetch --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

:robot: Bug found in 21 minutes bisecting 8 commits at 0 commits per second

litlighilit commented 1 week ago

not sure why in C backend it compiles,

as I found no / for int64, there seems to be only int/int in system.

litlighilit commented 1 week ago

not sure why in C backend it compiles,\n\nas I found no / for int64, there seems to be only int/int in system.

It compiles in C backend because, at least in x64 the operators of / is converted to int first, a.k.a. that's rewriten roughly as:

echo int(1.int64) / int(2.int64)

donno what will happened on 32 bit machine. 🤔