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

Macros cannot use constant under certain circumstances #16969

Open
inad9300 opened this issue Feb 1, 2025 · 0 comments
Open

Macros cannot use constant under certain circumstances #16969

inad9300 opened this issue Feb 1, 2025 · 0 comments
Labels
bug Something isn't working macros

Comments

@inad9300
Copy link
Contributor

inad9300 commented Feb 1, 2025

What version of Bun is running?

1.2.2+c1708ea6a

What platform is your computer?

Darwin 21.6.0 x86_64 i386

What steps can reproduce the bug?

macro.ts

const two = 2

export function add2(n: number) {
   return n + two
}

main.ts

import { add2 } from './macro' with { type: 'macro' }

// Works
console.log(add2(40))

// Doesn't
const data = 40
console.log(add2(data))
bun run main.ts

What is the expected behavior?

To be able to use static data from macros.

What do you see instead?

8 | console.log(add2(data))
                ^
error: "Cannot convert identifier to JS. Try a statically-known value" error in macro
    at .../main.ts:8:13

Bun v1.2.2 (macOS x64)

Additional information

No response

@inad9300 inad9300 added bug Something isn't working needs triage labels Feb 1, 2025
@inad9300 inad9300 changed the title Macros cannot use Macros cannot use constant under certain circumstances Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working macros
Projects
None yet
Development

No branches or pull requests

2 participants