RFCs icon indicating copy to clipboard operation
RFCs copied to clipboard

Procedures from system should have a lower priority then procedures from outside system.

Open solo989 opened this issue 5 years ago • 8 comments

Procedures created outside of system should have higher priority then procedures created inside system. If an ambiguity error would be thrown the procedure created outside of system would be chosen over any procedures defined in system.

Any additions to the standard library shouldn't cause conflicts with procedures defined in user code. This would be minimized if user defined procedures took priority.

I noticed this problem when I recently switched from the standard gc to arc and my overwrite of repr(NimNode) was causing ambiguity errors. I also tried to overwrite $(type) but ultimately made by own toStr procedure for types.

This can be worked around by putting import system except repr,$ at the top of your file but unfortunately that also drops a lot of other useful procedures. Also requiring users of your code to do this as well in the case of generics would be tedious. You could also qualify imports with myModule.repr.

solo989 avatar Oct 17 '20 04:10 solo989

Other solutions:

  • stop adding stuff to system.nim.
  • don't overwrite 'repr' or '$', use your own names.

But what you propose makes sense too.

Araq avatar Oct 17 '20 12:10 Araq

Could we prioritize based on import order, with system/other default imports being at the lowest priority? If you use from import then only the symbols you import would have priority.

metagn avatar Oct 31 '20 07:10 metagn

I'd prefer that users special-cased this stuff rather than having Nim always behave inconsistently merely for convenience of lazy users.

disruptek avatar Oct 31 '20 15:10 disruptek

This can be worked around by putting import system except repr,$ at the top of your file but unfortunately that also drops a lot of other useful procedures.

We should instead allow specifying overloads in import/export syntax, eg:

import foo except `$`(a: Bar)
from foo import `$`(a: Bar1), `$`(a: Bar2)
export `$(a: Bar3)`

for system this could work as follows, since string + friends is not yet defined:

from system import nil
import system except `$`(a: system.string)

This doesn't special case system nor introduce a priority amongst imports, which sounds like a can of worms unless you can describe exactly how that would work.

timotheecour avatar Oct 31 '20 18:10 timotheecour

While that sounds useful it's not required either. This works:


import system except repr
echo system.repr(12)

Araq avatar Nov 01 '20 06:11 Araq

it's not required either.

OP also mentioned $:

I also tried to overwrite $(type) but ultimately made by own toStr procedure for types. putting import system except repr,$ at the top of your file but unfortunately that also drops a lot of other useful procedures

timotheecour avatar Nov 01 '20 07:11 timotheecour

We should instead allow specifying overloads in import/export syntax

Can we have a separate RFC for this? I think this could be very useful and I'd like to hear separate opinions about it.

metagn avatar Nov 22 '20 10:11 metagn

This RFC is stale because it has been open for 1095 days with no activity. Contribute a fix or comment on the issue, or it will be closed in 30 days.

github-actions[bot] avatar Nov 23 '23 02:11 github-actions[bot]