unison icon indicating copy to clipboard operation
unison copied to clipboard

Ability constructors don't round-trip correctly if there's ambiguity

Open alvaroc1 opened this issue 2 years ago • 1 comments

This code:

unique ability canvas.SpriteBuffer where
  add : Sprite -> SpriteRef
  drawBuffer : '('{Canvas} ())

Produces this (as expected):

.alvaro> ls canvas.SpriteBuffer

  1. add        (Sprite ->{SpriteBuffer} SpriteRef)
  2. drawBuffer ('{SpriteBuffer} ('{Canvas} ()))

But when I view/edit it shows like this (incorrect? note the prefix in first constructor):

unique ability SpriteBuffer where
  SpriteBuffer.add : Sprite ->{SpriteBuffer} SpriteRef
  drawBuffer : '{SpriteBuffer} ('{Canvas} ())

Presumably because there's other terms named add (?).

And if I save it like that, it produces this:

.alvaro> ls canvas.SpriteBuffer

  1. SpriteBuffer/
  2. drawBuffer ('{SpriteBuffer} ('{Canvas} ()))

The add constructor has been placed in a new namespace :(

alvaroc1 avatar Jul 19 '22 02:07 alvaroc1

Good catch. I think I see the problem. It's in DeclPrinter:

    constructor (n, (_, _, t)) =
      prettyPattern env ctorType name (ConstructorReference r n)
        <> (fmt S.TypeAscriptionColon " :")
        `P.hang` TypePrinter.pretty0 env Map.empty (-1) t

So this is just printing out the name of the constructor, when it should be deducting the type name if it exists as a prefix of that constructor's chosen name.

pchiusano avatar Jul 19 '22 03:07 pchiusano