aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/underspecs_SUITE_data
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2014-08-19 16:16:08 +0200
committerHans Bolinder <[email protected]>2014-08-20 16:53:56 +0200
commit6e422d499fe079b87cfa226491b11016f36b9a31 (patch)
tree1b795507c5c1a4eff77ddf0991669a71154b9e67 /lib/dialyzer/test/underspecs_SUITE_data
parentc56edba2912e12f15226a1e130fdfac25c29b98f (diff)
downloadotp-6e422d499fe079b87cfa226491b11016f36b9a31.tar.gz
otp-6e422d499fe079b87cfa226491b11016f36b9a31.tar.bz2
otp-6e422d499fe079b87cfa226491b11016f36b9a31.zip
dialyzer: fix a -Wunderspecs bug
Sometimes bogus warnings were generated for parametrized types. Thanks to Krzesimir Sarnecki for pointing the bug out. Also corrected warnings where the structure of opaque types were exposed (thanks to Kostis for pointing the bug out).
Diffstat (limited to 'lib/dialyzer/test/underspecs_SUITE_data')
-rw-r--r--lib/dialyzer/test/underspecs_SUITE_data/results/arr4
-rw-r--r--lib/dialyzer/test/underspecs_SUITE_data/src/arr.erl41
2 files changed, 45 insertions, 0 deletions
diff --git a/lib/dialyzer/test/underspecs_SUITE_data/results/arr b/lib/dialyzer/test/underspecs_SUITE_data/results/arr
new file mode 100644
index 0000000000..9497d12eec
--- /dev/null
+++ b/lib/dialyzer/test/underspecs_SUITE_data/results/arr
@@ -0,0 +1,4 @@
+
+arr.erl:14: Type specification arr:test2(array:array(T),non_neg_integer(),T) -> array:array(T) is a supertype of the success typing: arr:test2(array:array(_),pos_integer(),_) -> array:array(_)
+arr.erl:24: Type specification arr:test4(array:array(T),non_neg_integer(),_) -> array:array(T) is a supertype of the success typing: arr:test4(array:array(_),pos_integer(),_) -> array:array(_)
+arr.erl:29: Type specification arr:test5(array:array(T),non_neg_integer(),T) -> array:array(T) is a supertype of the success typing: arr:test5(array:array(_),non_neg_integer(),integer()) -> array:array(_)
diff --git a/lib/dialyzer/test/underspecs_SUITE_data/src/arr.erl b/lib/dialyzer/test/underspecs_SUITE_data/src/arr.erl
new file mode 100644
index 0000000000..3b265ccec2
--- /dev/null
+++ b/lib/dialyzer/test/underspecs_SUITE_data/src/arr.erl
@@ -0,0 +1,41 @@
+-module(arr).
+
+%% http://erlang.org/pipermail/erlang-questions/2014-August/080445.html
+
+-define(A, array).
+
+-export([test/3, test2/3, test3/3, test4/3, test5/3, test6/3]).
+
+-spec test(?A:array(T), non_neg_integer(), T) -> ?A:array(T).
+
+test(Array, N, Value) ->
+ ?A:set(N, Value, Array).
+
+-spec test2(?A:array(T), non_neg_integer(), T) -> ?A:array(T).
+
+test2(Array, N, Value) when N > 0 ->
+ ?A:set(N, Value, Array).
+
+-spec test3(?A:array(T), non_neg_integer(), _) -> ?A:array(T).
+
+test3(Array, N, Value) ->
+ ?A:set(N, Value, Array).
+
+-spec test4(?A:array(T), non_neg_integer(), _) -> ?A:array(T).
+
+test4(Array, N, Value) when N > 0 ->
+ ?A:set(N, Value, Array).
+
+-spec test5(?A:array(T), non_neg_integer(), T) -> ?A:array(T).
+
+test5(Array, N, Value) when is_integer(Value) ->
+ ?A:set(N, Value, Array).
+
+%% One would ideally want a warning also for test6(), but the current
+%% analysis of parametrized opaque types is not strong enough to
+%% discover this.
+-spec test6(?A:array(integer()), non_neg_integer(), integer()) ->
+ ?A:array(any()).
+
+test6(Array, N, Value) ->
+ ?A:set(N, Value, Array).