unison/unison-src/transcripts/resolution-failures.output.md
Arya Irani 0cd3cd1cff Merge branch 'trunk' into cp/project-root
# Conflicts:
#	unison-cli-integration/integration-tests/IntegrationTests/transcript.output.md
#	unison-src/transcripts-round-trip/main.output.md
#	unison-src/transcripts/add-run.output.md
#	unison-src/transcripts/bug-strange-closure.output.md
#	unison-src/transcripts/cycle-update-5.output.md
#	unison-src/transcripts/delete.output.md
#	unison-src/transcripts/diff-namespace.output.md
#	unison-src/transcripts/move-namespace.output.md
#	unison-src/transcripts/name-selection.output.md
#	unison-src/transcripts/names.output.md
#	unison-src/transcripts/namespace-dependencies.output.md
#	unison-src/transcripts/propagate.output.md
#	unison-src/transcripts/reflog.output.md
#	unison-src/transcripts/reset.output.md
#	unison-src/transcripts/tab-completion.output.md
#	unison-src/transcripts/transcript-parser-commands.output.md
2024-07-10 23:49:04 -04:00

2.9 KiB

Resolution Errors

This transcript tests the errors printed to the user when a name cannot be resolved.

Codebase Setup

scratch/main> builtins.merge lib.builtins

  Done.

First we define differing types with the same name in different namespaces:

unique type one.AmbiguousType = one.AmbiguousType
unique type two.AmbiguousType = two.AmbiguousType

one.ambiguousTerm = "term one"
two.ambiguousTerm = "term two"

  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 one.AmbiguousType
      type two.AmbiguousType
      one.ambiguousTerm : Text
      two.ambiguousTerm : Text

scratch/main> add

  ⍟ I've added these definitions:
  
    type one.AmbiguousType
    type two.AmbiguousType
    one.ambiguousTerm : Text
    two.ambiguousTerm : Text

Tests

Now we introduce code which isn't sufficiently qualified. It is ambiguous which type from which namespace we mean.

We expect the output to:

  1. Print all ambiguous usage sites separately
  2. Print possible disambiguation suggestions for each unique ambiguity
-- We intentionally avoid using a constructor to ensure the constructor doesn't
-- affect type resolution.
useAmbiguousType : AmbiguousType -> ()
useAmbiguousType _ = ()

useUnknownType : UnknownType -> ()
useUnknownType _ = ()

-- Despite being a duplicate disambiguation, this should still be included in the annotations printout
separateAmbiguousTypeUsage : AmbiguousType -> ()
separateAmbiguousTypeUsage _ = ()

  Loading changes detected in scratch.u.

  
    ❓
    
    I couldn't resolve any of these symbols:
    
        3 | useAmbiguousType : AmbiguousType -> ()
        4 | useAmbiguousType _ = ()
        5 | 
        6 | useUnknownType : UnknownType -> ()
        7 | useUnknownType _ = ()
        8 | 
        9 | -- Despite being a duplicate disambiguation, this should still be included in the annotations printout
       10 | separateAmbiguousTypeUsage : AmbiguousType -> ()
    
    
    Symbol          Suggestions
                    
    AmbiguousType   one.AmbiguousType
                    two.AmbiguousType
                    
    UnknownType     No matches
  

Currently, ambiguous terms are caught and handled by type directed name resolution, but expect it to eventually be handled by the above machinery.

useAmbiguousTerm = ambiguousTerm

  Loading changes detected in scratch.u.

  I couldn't figure out what ambiguousTerm refers to here:
  
      1 | useAmbiguousTerm = ambiguousTerm
  
  The name ambiguousTerm is ambiguous. I couldn't narrow it down
  by type, as any type would work here.
  
  I found some terms in scope that have matching names and
  types. Maybe you meant one of these:
  
  one.ambiguousTerm : Text
  two.ambiguousTerm : Text