Skip to content

Commit 562d30e

Browse files
VLanvinmeta-codesync[bot]
authored andcommitted
Snapshots Pat = Var = Expr
Summary: Snapshot tests for exprs of the form `Pat = Var = Expr`. Reviewed By: michalmuskala Differential Revision: D84819136 fbshipit-source-id: a229e453ea48d2bb6b0b45ad430d362b765f58ee
1 parent 07fe4f7 commit 562d30e

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
2+
┌─ check/src/pats.erl:21:17
3+
4+
21 │ maps:get(a, M).
5+
│ ^
6+
│ │
7+
│ M.
8+
Expression has type: #{a => 'ok'} | 'error'
9+
Context expected type: #{term() => term()}
10+
11+
12+
Because in the expression's type:
13+
Here the type is a union type with some valid candidates: #{a => 'ok'}
14+
However the following candidate: 'error'
15+
Differs from the expected type: #{term() => term()}
16+
17+
------------------------------ Detailed message ------------------------------
18+
19+
#{a => 'ok'} | 'error' is not compatible with #{term() => term()}
20+
because
21+
'error' is not compatible with #{term() => term()}
22+
23+
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
24+
┌─ check/src/pats.erl:26:17
25+
26+
26 │ maps:get(a, M).
27+
│ ^
28+
│ │
29+
│ M.
30+
Expression has type: #{a => 'ok'} | 'error'
31+
Context expected type: #{term() => term()}
32+
33+
34+
Because in the expression's type:
35+
Here the type is a union type with some valid candidates: #{a => 'ok'}
36+
However the following candidate: 'error'
37+
Differs from the expected type: #{term() => term()}
38+
39+
------------------------------ Detailed message ------------------------------
40+
41+
#{a => 'ok'} | 'error' is not compatible with #{term() => term()}
42+
because
43+
'error' is not compatible with #{term() => term()}
44+
45+
2 ERRORS
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
2+
┌─ check/src/pats.erl:21:17
3+
4+
21 │ maps:get(a, M).
5+
│ ^
6+
│ │
7+
│ M.
8+
Expression has type: #{a => 'ok'} | 'error'
9+
Context expected type: #{term() => term()}
10+
11+
12+
Because in the expression's type:
13+
Here the type is a union type with some valid candidates: #{a => 'ok'}
14+
However the following candidate: 'error'
15+
Differs from the expected type: #{term() => term()}
16+
17+
------------------------------ Detailed message ------------------------------
18+
19+
#{a => 'ok'} | 'error' is not compatible with #{term() => term()}
20+
because
21+
'error' is not compatible with #{term() => term()}
22+
23+
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
24+
┌─ check/src/pats.erl:26:17
25+
26+
26 │ maps:get(a, M).
27+
│ ^
28+
│ │
29+
│ M.
30+
Expression has type: #{a => 'ok'} | 'error'
31+
Context expected type: #{term() => term()}
32+
33+
34+
Because in the expression's type:
35+
Here the type is a union type with some valid candidates: #{a => 'ok'}
36+
However the following candidate: 'error'
37+
Differs from the expected type: #{term() => term()}
38+
39+
------------------------------ Detailed message ------------------------------
40+
41+
#{a => 'ok'} | 'error' is not compatible with #{term() => term()}
42+
because
43+
'error' is not compatible with #{term() => term()}
44+
45+
2 ERRORS
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
2+
┌─ check/src/pats.erl:21:17
3+
4+
21 │ maps:get(a, M).
5+
│ ^
6+
│ │
7+
│ M.
8+
Expression has type: #{a => 'ok'} | 'error'
9+
Context expected type: #{term() => term()}
10+
11+
12+
Because in the expression's type:
13+
Here the type is a union type with some valid candidates: #{a => 'ok'}
14+
However the following candidate: 'error'
15+
Differs from the expected type: #{term() => term()}
16+
17+
------------------------------ Detailed message ------------------------------
18+
19+
#{a => 'ok'} | 'error' is not compatible with #{term() => term()}
20+
because
21+
'error' is not compatible with #{term() => term()}
22+
23+
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
24+
┌─ check/src/pats.erl:26:17
25+
26+
26 │ maps:get(a, M).
27+
│ ^
28+
│ │
29+
│ M.
30+
Expression has type: #{a => 'ok'} | 'error'
31+
Context expected type: #{term() => term()}
32+
33+
34+
Because in the expression's type:
35+
Here the type is a union type with some valid candidates: #{a => 'ok'}
36+
However the following candidate: 'error'
37+
Differs from the expected type: #{term() => term()}
38+
39+
------------------------------ Detailed message ------------------------------
40+
41+
#{a => 'ok'} | 'error' is not compatible with #{term() => term()}
42+
because
43+
'error' is not compatible with #{term() => term()}
44+
45+
2 ERRORS
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
%%% Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.
2+
%%%
3+
%%% This source code is licensed under the Apache 2.0 license found in
4+
%%% the LICENSE file in the root directory of this source tree.
5+
6+
-module(pats).
7+
8+
-compile([export_all, nowarn_export_all]).
9+
10+
-spec return_map() -> #{a => ok} | error.
11+
return_map() -> #{a => ok}.
12+
13+
-spec patmatch1() -> ok.
14+
patmatch1() ->
15+
#{a := V} = _M = return_map(),
16+
V.
17+
18+
-spec patmatch2() -> ok.
19+
patmatch2() ->
20+
#{a := _V} = M = return_map(),
21+
maps:get(a, M).
22+
23+
-spec patmatch3_neg() -> ok.
24+
patmatch3_neg() ->
25+
_V = M = return_map(),
26+
maps:get(a, M).
27+
28+
-spec patmatch4() -> ok.
29+
patmatch4() ->
30+
M = #{a := _V} = return_map(),
31+
maps:get(a, M).

0 commit comments

Comments
 (0)