-module(parameterized_tuple). -export([mk_type1/0, mk_type2/0]). -export([test1/0, test2/0, test3/0, test4/0]). -export_type([my_record/1, my_record/0, my_rec_type/0]). -define(TYPE1, 1). -define(TYPE2, 2). -type my_record(Type) :: {my_tag, Id :: integer(), Type}. -type my_record() :: my_record(my_rec_type()). -type my_rec_type() :: ?TYPE1..?TYPE2. -spec mk_type1() -> my_record(?TYPE1). mk_type1() -> {my_tag, rand:uniform(10), ?TYPE1}. -spec mk_type2() -> my_record(?TYPE2). mk_type2() -> {my_tag, rand:uniform(10), ?TYPE2}. test1() -> Rec2 = mk_type2(), take_type1(Rec2). %expects ?TYPE1, gets ?TYPE2. Reported! -spec take_type1(my_record(?TYPE1)) -> ok. take_type1(Rec) -> gen_server:call(somewhere, Rec). test2() -> Rec2 = mk_type2(), take_type1_rec(Rec2). %expects ?TYPE1, gets ?TYPE2. Reported! -spec take_type1_rec({my_tag, integer(), ?TYPE1}) -> ok. take_type1_rec(Rec) -> gen_server:call(somewhere, Rec). test3() -> should_make_type2(). %spec says returns ?TYPE2, returns ?TYPE1. Reported! -spec should_make_type2() -> my_record(?TYPE2). should_make_type2() -> mk_type1(). test4() -> should_make_type2_rec(). %spec says returns ?TYPE2, returns ?TYPE1. Reported! -spec should_make_type2_rec() -> {my_tag, integer(), ?TYPE2}. should_make_type2_rec() -> mk_type1().