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

'internal error: proc has no result symbol' when using operators as first-class functions #24616

Open
maxgrenderjones opened this issue Jan 14, 2025 · 1 comment

Comments

@maxgrenderjones
Copy link
Contributor

Description

Code that triggers compiler error:

import strformat
import sugar

let val = "+"
let op: (int, int) -> int = case val:
    of "+": `+`
    of "/": `div`
    of "*": `*`
    else: raise newException(ValueError, fmt"Unhandled operator: {val}")

It's not the fault of sugar as you get the same error with:

import strformat

let val = "+"
let op: proc(x: int, y: int): int = case val:
    of "+": `+`
    of "/": `div`
    of "*": `*`
    else: raise newException(ValueError, fmt"Unhandled operator: {val}")

Error:

» nim c src/compiler.nim
Hint: used config file '/opt/homebrew/Cellar/nim/2.2.0/nim/config/nim.cfg' [Conf]
Hint: used config file '/opt/homebrew/Cellar/nim/2.2.0/nim/config/config.nims' [Conf]
........................................................................................
/opt/homebrew/Cellar/nim/2.2.0/nim/lib/system/arithmetics.nim(75, 6) Error: internal error: proc has no result symbol
No stack traceback available
To create a stacktrace, rerun compilation with './koch temp c <file>', see https://nim-lang.github.io/Nim/intern.html#debugging-the-compiler for details

Nim Version

» nim -v
Nim Compiler Version 2.2.0 [MacOSX: arm64]
Compiled at 2024-10-02
Copyright (c) 2006-2024 by Andreas Rumpf

active boot switches: -d:release -d:nimUseLinenoise

Current Output

No response

Expected Output

No response

Known Workarounds

No response

Additional Information

No response

@metagn
Copy link
Collaborator

metagn commented Jan 15, 2025

`+` etc cannot be used as first class functions, they are magic procs and map to the backend operators. This should give a proper error message

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