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.49k stars 1.46k forks source link

Macro with name `on` unexpected behaviour #7857

Open coffeepots opened 6 years ago

coffeepots commented 6 years ago

Module A:

macro ona*(body: untyped): untyped =
  discard

macro on*(body: untyped): untyped =
  discard

Module B:

import modulea

ona:
  echo "a" # no problem

on:
  echo "b" # Error: expression 'echo ["b"]' has no type (or is ambiguous)

Changing the name of the macro from on fixes the problem.

data-man commented 6 years ago

For off the same.

arnetheduck commented 6 years ago

isn't this because https://github.com/nim-lang/Nim/blob/a39b989ce238546eca64e9c37734bc48f61e280c/lib/system.nim#L56?

Araq commented 6 years ago

Yeah, but I wonder why overloading resolution picks up consts. :-)

metagn commented 1 month ago

It finds system.on first then calls semIndirectOp which calls semOpAux which typechecks all the arguments.

Maybe other symbols should also call semDirectOp/semMagic the same way ambiguous type symbols do