Skip to content

Commit

Permalink
more precise handling of maps:remove
Browse files Browse the repository at this point in the history
Summary: More precise handling of `maps:remove(Key, Map)` when `Map` is a shape and `Key` is not an atom literal: it makes all the associations in `Map` optional instead of converting to a dictionary.

Reviewed By: VLanvin

Differential Revision: D57205786

fbshipit-source-id: b775b49ff48fb171b24f9880d2816dc1108f30c9
  • Loading branch information
ilya-klyuchnikov authored and facebook-github-bot committed May 10, 2024
1 parent ffabb9f commit ec3c430
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ class ElabApplyCustom(pipelineContext: PipelineContext) {
val props = shape.props.filter(_.key != key)
shape.copy(props = props)
case _ =>
val valTy = subtype.join(shape.props.map(_.tp))
DictMap(AtomType, valTy)
ShapeMap(shape.props.map { case ReqProp(k, v) => OptProp(k, v); case prop => prop })
}
case UnionType(tys) =>
subtype.join(tys.map(remove))
Expand Down
11 changes: 9 additions & 2 deletions eqwalizer/test_projects/check/src/custom.erl.check
Original file line number Diff line number Diff line change
Expand Up @@ -2920,8 +2920,15 @@ maps_remove2(M) -> | OK |
) -> #{a := integer()}. | |
maps_remove3_neg(A, M) -> | ERROR |
maps:remove(A, M). | | maps:remove(A, M).
| | Expression has type: dict map #D{atom() => number()}
| | Context expected type: shape map #S{a := number()}
| | Expression has type: #S{a => number()}
| | Context expected type: #S{a := number()}
| |
| | These associations do not match:
| |
| | #S{
| | - a := ...
| | + a => ...
| | }
| |
-spec maps_remove4( | |
#{a := integer(), b := atom()} | | |
Expand Down

0 comments on commit ec3c430

Please sign in to comment.