unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

Kind error using a phantom type variable for abilities #5410

Open ceedubs opened 1 month ago

ceedubs commented 1 month ago

Describe and demonstrate the bug

If you add a phantom type variable to a data type, it always seems to be recognized as a Type type parameter, but you might want it to be an Ability type parameter.

Input:

```unison
type Location g = Location
fresh/main> add
main = do
  x : Location {}
  x = Location

Output:
```` markdown
``` unison
type Location g = Location

  Loading changes detected in scratch.u.

  I found and typechecked these definitions in scratch.u. If you
  do an `add` or `update`, here's how your codebase would
  change:

    ⍟ These new definitions are ok to `add`:

      type Location g
fresh/main> add

  ⍟ I've added these definitions:

    type Location g
main = do
  x : Location {}
  x = Location

  Loading changes detected in scratch.u.

  Kind mismatch arising from
        2 |   x : Location {}

    Location expects an argument of kind: Type; however, it is
    applied to which has kind: Ability.

πŸ›‘

The transcript failed due to an error in the stanza above. The error is:

Kind mismatch arising from 2 | x : Location {}

Location expects an argument of kind: Type; however, it is
applied to which has kind: Ability.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment (please complete the following information):**
 - `ucm --version` e2c42cac4

**Additional context**

I managed to get a variation of this to compile (probably through unsafe/unsound means that I'm unable to replicate in a transcript), and _running_ the code doesn't cause issues, but when the value is returned from a `run` call, it generates the following error:

@unison/cloud/blobstore> run tmp Encountered exception: synthesizeForce fails although fitsScheme passed Input Type: ReferenceDerived (Id "00nv2kob8fp11qdkr750rlppf81cda95m3q0niohj1pvljnjl4r3hqrhvp1un2p40ptgkhhsne7hocod90r3qdlus9guivh7j3qcq0g" 0) -> ({[ReferenceBuiltin "IO",ReferenceDerived (Id "4n0fgs00hpsj3paqnm9bfm4nbt9cbrin3hl88i992m9tjiq1ik7eq72asu4hcg885uti36tbnj5rudt56eahhnut1nobofg86pk1bng" 0)]} ReferenceDerived (Id "prrhin67cemaummdiu0c35cj17g8m7t96qne5i8vfj9m6ur338250jukj6q33ob0llgl9vvgc50rfgiiu7u0nvg5fvajkpqa0amjct0" 0) (ReferenceDerived (Id "ff2hucvrmnv454rjlj3inrn526njb1th979js4a6m1uo314fpogfbtsadifeei3t7e6v315isgi5ueokqvatdbpobe3hmtt9o0bk77o" 0) ({[]}))) Notes: Notes {bugs = fromList [], errors = fromList [ErrorNote {cause = KindInferenceFailure kind error, path = fromList []}], infos = fromList []}



The error goes away if I simply add a `()` as the return value of my main method instead of an instance of the [Location type from @unison/cloud](https://share.unison-lang.org/@unison/cloud/code/releases/18.5.1/latest/types/Remote/Location)