-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5282 from sellout/fix-blank-identifiers
Change handling of “blank” identifiers
- Loading branch information
Showing
5 changed files
with
269 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Inability to reference a term or type with a name that has segments starting with an underscore | ||
|
||
```ucm:hide | ||
scratch/main> builtins.mergeio | ||
``` | ||
|
||
There should be no issue having terms with an underscore-led component | ||
|
||
```unison | ||
_a.blah = 2 | ||
b = _a.blah + 1 | ||
``` | ||
|
||
Or even that _are_ a single “blank” component | ||
|
||
```unison | ||
_b = 2 | ||
x = _b + 1 | ||
``` | ||
Types can also have underscore-led components. | ||
|
||
```unison | ||
unique type _a.Blah = A | ||
c : _a.Blah | ||
c = A | ||
``` | ||
|
||
And we should also be able to access underscore-led fields. | ||
|
||
```unison | ||
type Hello = {_value : Nat} | ||
doStuff = _value.modify | ||
``` | ||
|
||
But pattern matching shouldn’t bind to underscore-led names. | ||
|
||
```unison:error | ||
dontMap f = cases | ||
None -> false | ||
Some _used -> f _used | ||
``` | ||
|
||
But we can use them as unbound patterns. | ||
|
||
```unison | ||
dontMap f = cases | ||
None -> false | ||
Some _unused -> f 2 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# Inability to reference a term or type with a name that has segments starting with an underscore | ||
|
||
There should be no issue having terms with an underscore-led component | ||
|
||
``` unison | ||
_a.blah = 2 | ||
b = _a.blah + 1 | ||
``` | ||
|
||
``` ucm | ||
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`: | ||
_a.blah : Nat | ||
b : Nat | ||
``` | ||
Or even that *are* a single “blank” component | ||
|
||
``` unison | ||
_b = 2 | ||
x = _b + 1 | ||
``` | ||
|
||
``` ucm | ||
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`: | ||
_b : Nat | ||
x : Nat | ||
``` | ||
Types can also have underscore-led components. | ||
|
||
``` unison | ||
unique type _a.Blah = A | ||
c : _a.Blah | ||
c = A | ||
``` | ||
|
||
``` ucm | ||
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 _a.Blah | ||
c : Blah | ||
``` | ||
And we should also be able to access underscore-led fields. | ||
|
||
``` unison | ||
type Hello = {_value : Nat} | ||
doStuff = _value.modify | ||
``` | ||
|
||
``` ucm | ||
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 Hello | ||
Hello._value : Hello -> Nat | ||
Hello._value.modify : (Nat ->{g} Nat) -> Hello ->{g} Hello | ||
Hello._value.set : Nat -> Hello -> Hello | ||
doStuff : (Nat ->{g} Nat) -> Hello ->{g} Hello | ||
``` | ||
But pattern matching shouldn’t bind to underscore-led names. | ||
|
||
``` unison | ||
dontMap f = cases | ||
None -> false | ||
Some _used -> f _used | ||
``` | ||
|
||
``` ucm | ||
Loading changes detected in scratch.u. | ||
I couldn't figure out what _used refers to here: | ||
3 | Some _used -> f _used | ||
I also don't know what type it should be. | ||
Some common causes of this error include: | ||
* Your current namespace is too deep to contain the | ||
definition in its subtree | ||
* The definition is part of a library which hasn't been | ||
added to this project | ||
* You have a typo in the name | ||
``` | ||
But we can use them as unbound patterns. | ||
|
||
``` unison | ||
dontMap f = cases | ||
None -> false | ||
Some _unused -> f 2 | ||
``` | ||
|
||
``` ucm | ||
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`: | ||
dontMap : (Nat ->{g} Boolean) -> Optional a ->{g} Boolean | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.