treeform / jsony

A loose, direct to object json parser with hooks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jsony 1.1.0: surprising re-definition of 'SomeSet'; ambiguous identifer error

ee7 opened this issue · comments

commented

Hey @treeform. Thanks for your great packages.

Example

Consider a typical Nim user who reads:

proc parseHook*[T](s: string, i: var int, v: var SomeSet[T]) =

proc dumpHook*[T](s: var string, v: SomeSet[T]) =

Expectation

They think that jsony does not support the built-in set type, because they're familiar with the definition in std/sets of just:

  SomeSet*[A] = HashSet[A] | OrderedSet[A]

Reality

jsony does support the set type, it's just that since commit ebee42e, jsony exports its own SomeSet type that includes set:

jsony/src/jsony.nim

Lines 10 to 14 in d7070a7

type
SomeTable*[K, V] = Table[K, V] | OrderedTable[K, V] |
TableRef[K, V] | OrderedTableRef[K, V]
SomeSet*[A] = HashSet[A] | OrderedSet[A] | set[A]

Discussion

Would it be better to go back to this instead?

proc parseHook*[T](s: string, i: var int, v: var (SomeSet[T]|set[T]))

This would also allow jsony to be used again with code that uses SomeSet. For example, this:

import std/sets
import pkg/jsony

proc foo[A](s: SomeSet[A]) =
  discard

compiled with jsony 1.0.5 and earlier, but doesn't compile with jsony 1.1.0:

/tmp/foo.nim(4, 16) Error: ambiguous identifier: 'SomeSet' -- use one of the following:
  sets.SomeSet: SomeSet
  jsony.SomeSet: SomeSet

This is why I started creating this issue - I saw exactly this breakage when upgrading jsony.

Sure, it's easy for that user to replace SomeSet with sets.SomeSet everywhere in their existing code. But that doesn't seem like a great fix.

One alternative is to rename the new exported type, but that's probably less obvious, and it might be hard to find a good name.

It's also not immediately obvious to every Nim user whether something like jsony.SomeSet[string] even compiles, because set[string] is not a valid type.

You raise a good point. I'll look into changing it back.

commented

Cool. Thanks.

I've created #34, in case that helps. But feel free to amend/close it at your convenience.