mirror of
https://github.com/unisonweb/unison.git
synced 2024-10-26 02:55:19 +03:00
Merge pull request #4752 from unisonweb/runarorama/fixFieldNames
Fix field accessors not showing up in `view` in some cases
This commit is contained in:
commit
d913a61f45
@ -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)
|
||||
|
@ -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`).
|
||||
|
@ -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
|
||||
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user