Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 10, 2026

import std/oids failed with JS backend due to std/endians calling copyMem, which doesn't exist in JS.

Changes

lib/pure/endians.nim

  • Added JS-specific implementations using emit blocks for byte manipulation
  • Handles three JS pointer calling conventions:
    • addr(array)(Uint8Array)
    • addr(variable)(variable, 0)
    • addr(obj.field)(obj, "field")
  • Object fields copy values directly (byte-level manipulation not feasible for JS scalars)

tests/js/tstdlib_imports.nim

  • Enabled oids and endians imports

Example

import std/oids

let oid = genOid()
echo $oid  # Now works with JS backend

Previously this would fail at compile time with Error: undeclared identifier: 'copyMem'.

Original prompt

This section details on the original issue you should resolve

<issue_title>Ambiguous error when importing lib std/oids with js backend</issue_title>
<issue_description>### Description

Hey, sometimes I accidentally import some modules that do not work with js backend, but the error I get is rather confusing, I spend a lot of time figuring out what piece of code causes this problem.

import std/oids

This is confusing because the module oids does not imported directly.

Nim Version

Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2023-08-13
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 9207d77

Current Output

/home/hamidb80/.choosenim/toolchains/nim-#devel/lib/pure/endians.nim(131, 57) Error: undeclared identifier: 'copyMem'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (4, 4): '=copy'
 (4, 4): 'compiles'
 (4, 4): 'ctypes'

Expected Output

the above error + something that shows module import hierarchy

Foot Note

why std/oids should not work with JS??
</issue_description>

<agent_instructions>implements it for JS backend
test it with ./koch temp js -r test.nim</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@ringabout PR is welcome.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix ambiguous error when importing lib std/oids with js backend Enable std/oids and std/endians for JS backend Jan 10, 2026
Copilot AI requested a review from ringabout January 10, 2026 07:59
@ringabout ringabout closed this Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ambiguous error when importing lib std/oids with js backend

2 participants