Merge pull request #4752 from unisonweb/runarorama/fixFieldNames

Fix field accessors not showing up in `view` in some cases
This commit is contained in:
Arya Irani 2024-03-08 10:09:09 -05:00 committed by GitHub
commit d913a61f45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 100 additions and 2 deletions

View File

@ -175,7 +175,10 @@ fieldNames env r name dd = do
[(_, typ)] -> Just typ
_ -> Nothing
let vars :: [v]
vars = [Var.freshenId (fromIntegral n) (Var.named "_") | n <- [0 .. Type.arity typ - 1]]
-- We add `n` to the end of the variable name as a quick fix to #4752, but we suspect there's a more
-- fundamental fix to be made somewhere in the term printer to automatically suffix a var name with its
-- freshened id if it would be ambiguous otherwise.
vars = [Var.freshenId (fromIntegral n) (Var.named ("_" <> Text.pack (show n))) | n <- [0 .. Type.arity typ - 1]]
hashes <- DD.hashFieldAccessors env (HQ.toVar name) vars r dd
let names =
[ (r, HQ.toText . PPE.termName env . Referent.Ref $ DerivedId r)

View File

@ -69,6 +69,42 @@ unique type Record4 =
.> view Record4
```
## Record with many many fields
```unison:hide
unique type Record5 = {
zero : Nat,
one : [Nat],
two : [[Nat]],
three: [[[Nat]]],
four: [[[[Nat]]]],
five: [[[[[Nat]]]]],
six: [[[[[[Nat]]]]]],
seven: [[[[[[[Nat]]]]]]],
eight: [[[[[[[[Nat]]]]]]]],
nine: [[[[[[[[[Nat]]]]]]]]],
ten: [[[[[[[[[[Nat]]]]]]]]]],
eleven: [[[[[[[[[[[Nat]]]]]]]]]]],
twelve: [[[[[[[[[[[[Nat]]]]]]]]]]]],
thirteen: [[[[[[[[[[[[[Nat]]]]]]]]]]]]],
fourteen: [[[[[[[[[[[[[[Nat]]]]]]]]]]]]]],
fifteen: [[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]],
sixteen: [[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]],
seventeen: [[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]],
eighteen: [[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]],
nineteen: [[[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]]],
twenty: [[[[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]]]]
}
```
```ucm:hide
.> add
```
```ucm
.> view Record5
```
## Record with user-defined type fields
This record type has two fields whose types are user-defined (`Record4` and `UserType`).

View File

@ -62,6 +62,61 @@ unique type Record4 =
f : Nat,
g : [Nat] }
```
## Record with many many fields
```unison
unique type Record5 = {
zero : Nat,
one : [Nat],
two : [[Nat]],
three: [[[Nat]]],
four: [[[[Nat]]]],
five: [[[[[Nat]]]]],
six: [[[[[[Nat]]]]]],
seven: [[[[[[[Nat]]]]]]],
eight: [[[[[[[[Nat]]]]]]]],
nine: [[[[[[[[[Nat]]]]]]]]],
ten: [[[[[[[[[[Nat]]]]]]]]]],
eleven: [[[[[[[[[[[Nat]]]]]]]]]]],
twelve: [[[[[[[[[[[[Nat]]]]]]]]]]]],
thirteen: [[[[[[[[[[[[[Nat]]]]]]]]]]]]],
fourteen: [[[[[[[[[[[[[[Nat]]]]]]]]]]]]]],
fifteen: [[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]],
sixteen: [[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]],
seventeen: [[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]],
eighteen: [[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]],
nineteen: [[[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]]],
twenty: [[[[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]]]]
}
```
```ucm
.> view Record5
type Record5
= { zero : Nat,
one : [Nat],
two : [[Nat]],
three : [[[Nat]]],
four : [[[[Nat]]]],
five : [[[[[Nat]]]]],
six : [[[[[[Nat]]]]]],
seven : [[[[[[[Nat]]]]]]],
eight : [[[[[[[[Nat]]]]]]]],
nine : [[[[[[[[[Nat]]]]]]]]],
ten : [[[[[[[[[[Nat]]]]]]]]]],
eleven : [[[[[[[[[[[Nat]]]]]]]]]]],
twelve : [[[[[[[[[[[[Nat]]]]]]]]]]]],
thirteen : [[[[[[[[[[[[[Nat]]]]]]]]]]]]],
fourteen : [[[[[[[[[[[[[[Nat]]]]]]]]]]]]]],
fifteen : [[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]],
sixteen : [[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]],
seventeen : [[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]],
eighteen : [[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]],
nineteen : [[[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]]],
twenty : [[[[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]]]] }
```
## Record with user-defined type fields
@ -103,7 +158,6 @@ unique type Record5 =
⍟ These new definitions are ok to `add`:
type Record5
Record5.a : Record5 -> Text
Record5.a.modify : (Text ->{g} Text)
-> Record5
@ -114,5 +168,10 @@ unique type Record5 =
-> Record5
->{g} Record5
Record5.b.set : Int -> Record5 -> Record5
⍟ These names already exist. You can `update` them to your
new definition:
type Record5
```