Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples of list comprehension generators being none() #434

Merged
merged 5 commits into from
Aug 22, 2022

Conversation

erszcz
Copy link
Collaborator

@erszcz erszcz commented Aug 11, 2022

This is a set of examples for #433 found based on the error message for typechecker:has_overlapping_keys/2 and tracing execution.

@erszcz
Copy link
Collaborator Author

erszcz commented Aug 11, 2022

A somewhat bigger example is:

-type type() :: erl_parse:abstract_type().

-spec f(type()) -> [x].
f({type, _, map, Assocs}) ->
    [ x || As1 <- Assocs, As2 <- Assocs, As1 /= As2 ].

The call to GLB which leads to the type of the generator being inferred as none() is

add_type_pat(Pat, ?type(union, UnionTys) = UnionTy, Env) ->
{PatTys, UBounds, Envs, Css} =
lists:foldr(fun (Ty, {PatTysAcc, UBoundsAcc, EnvAcc, CsAcc} = Acc) ->
%% Ty is normalized, since UnionTy is normalized
try add_type_pat(Pat, Ty, Env) of
{PatTy, UBound, NewEnv, Cs} ->
{[PatTy|PatTysAcc],
[UBound|UBoundsAcc],
[NewEnv|EnvAcc],
[Cs|CsAcc]}
catch _TypeError ->
Acc
end
end,
{[], [], [], []},
UnionTys),
case PatTys of
[] ->
%% Pattern doesn't match any type in the union
Anno = element(2, Pat),
throw(type_error(pattern, Anno, Pat, UnionTy));
_SomeTysMatched ->
%% TODO: The constraints should be merged with *or* semantics
%% and var binds with intersection
{Ty, Cs} = glb(PatTys, Env),

The corresponding trace is:

{trace,<0.86.0>,call,
    {typechecker,glb_ty,
        [{type,0,tuple,
             [{atom,0,type},
              {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
              {atom,0,map},
              {type,0,list,
                  [{user_type,
                       [{file,"erl_parse.erl"},{location,0}],
                       af_assoc_type,[]}]}]},
         {type,0,tuple,
             [{atom,0,type},
              {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
              {atom,0,map},
              {atom,0,any}]},
         #{{{type,0,tuple,
                [{atom,0,type},
                 {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
                 {atom,0,map},
                 {type,0,list,
                     [{user_type,
                          [{file,"erl_parse.erl"},{location,0}],
                          af_assoc_type,[]}]}]},
            {type,0,tuple,
                [{atom,0,type},
                 {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
                 {atom,0,map},
                 {atom,0,any}]}} =>
               0},
         {env,
             #{{f,1} =>
                   [{type,
                        {7,8},
                        bounded_fun,
                        [{type,
                             {7,8},
                             'fun',
                             [{type,{7,8},product,[{user_type,{7,9},type,[]}]},
                              {type,{7,20},list,[{atom,{7,21},x}]}]},
                         []]}]},
             #{},#{},
             #{module => lc,records => #{},
               types =>
                   #{{type,0} =>
                         {[],
                          {remote_type,0,
                              [{atom,{5,17},erl_parse},
                               {atom,{5,27},abstract_type},
                               []]}}}},
             false,false,true,
             [{clauses_controls,true}],
             30,
             [{type,
                  {7,8},
                  bounded_fun,
                  [{type,
                       {7,8},
                       'fun',
                       [{type,{7,8},product,[{user_type,{7,9},type,[]}]},
                        {type,{7,20},list,[{atom,{7,21},x}]}]},
                   []]}]}]}}
{trace,<0.86.0>,call,
    {typechecker,glb_ty,
        [{atom,0,type},
         {atom,0,type},
         #{{{atom,0,type},{atom,0,type}} => 0,
           {{type,0,tuple,
                [{atom,0,type},
                 {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
                 {atom,0,map},
                 {type,0,list,
                     [{user_type,
                          [{file,"erl_parse.erl"},{location,0}],
                          af_assoc_type,[]}]}]},
            {type,0,tuple,
                [{atom,0,type},
                 {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
                 {atom,0,map},
                 {atom,0,any}]}} =>
               0},
         {env,
             #{{f,1} =>
                   [{type,
                        {7,8},
                        bounded_fun,
                        [{type,
                             {7,8},
                             'fun',
                             [{type,{7,8},product,[{user_type,{7,9},type,[]}]},
                              {type,{7,20},list,[{atom,{7,21},x}]}]},
                         []]}]},
             #{},#{},
             #{module => lc,records => #{},
               types =>
                   #{{type,0} =>
                         {[],
                          {remote_type,0,
                              [{atom,{5,17},erl_parse},
                               {atom,{5,27},abstract_type},
                               []]}}}},
             false,false,true,
             [{clauses_controls,true}],
             30,
             [{type,
                  {7,8},
                  bounded_fun,
                  [{type,
                       {7,8},
                       'fun',
                       [{type,{7,8},product,[{user_type,{7,9},type,[]}]},
                        {type,{7,20},list,[{atom,{7,21},x}]}]},
                   []]}]}]}}
{trace,<0.86.0>,return_from,
       {typechecker,glb_ty,4},
       {{atom,0,type},
        {constraints,#{},#{},
                     {set,0,16,16,8,80,48,
                          {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
                          {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
                            []}}}}}}
{trace,<0.86.0>,return_to,{typechecker,glb,4}}
{trace,<0.86.0>,call,
    {typechecker,glb_ty,
        [{user_type,[{file,"erl_anno.erl"},{location,0}],anno,[]},
         {user_type,[{file,"erl_anno.erl"},{location,0}],anno,[]},
         #{{{type,0,tuple,
                [{atom,0,type},
                 {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
                 {atom,0,map},
                 {type,0,list,
                     [{user_type,
                          [{file,"erl_parse.erl"},{location,0}],
                          af_assoc_type,[]}]}]},
            {type,0,tuple,
                [{atom,0,type},
                 {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
                 {atom,0,map},
                 {atom,0,any}]}} =>
               0,
           {{user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
            {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]}} =>
               0},
         {env,
             #{{f,1} =>
                   [{type,
                        {7,8},
                        bounded_fun,
                        [{type,
                             {7,8},
                             'fun',
                             [{type,{7,8},product,[{user_type,{7,9},type,[]}]},
                              {type,{7,20},list,[{atom,{7,21},x}]}]},
                         []]}]},
             #{},#{},
             #{module => lc,records => #{},
               types =>
                   #{{type,0} =>
                         {[],
                          {remote_type,0,
                              [{atom,{5,17},erl_parse},
                               {atom,{5,27},abstract_type},
                               []]}}}},
             false,false,true,
             [{clauses_controls,true}],
             30,
             [{type,
                  {7,8},
                  bounded_fun,
                  [{type,
                       {7,8},
                       'fun',
                       [{type,{7,8},product,[{user_type,{7,9},type,[]}]},
                        {type,{7,20},list,[{atom,{7,21},x}]}]},
                   []]}]}]}}
{trace,<0.86.0>,return_from,
       {typechecker,glb_ty,4},
       {{user_type,[{file,"erl_anno.erl"},{location,0}],anno,[]},
        {constraints,#{},#{},
                     {set,0,16,16,8,80,48,
                          {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
                          {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
                            []}}}}}}
{trace,<0.86.0>,return_to,{typechecker,glb,4}}
{trace,<0.86.0>,call,
    {typechecker,glb_ty,
        [{atom,0,map},
         {atom,0,map},
         #{{{atom,0,map},{atom,0,map}} => 0,
           {{type,0,tuple,
                [{atom,0,type},
                 {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
                 {atom,0,map},
                 {type,0,list,
                     [{user_type,
                          [{file,"erl_parse.erl"},{location,0}],
                          af_assoc_type,[]}]}]},
            {type,0,tuple,
                [{atom,0,type},
                 {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
                 {atom,0,map},
                 {atom,0,any}]}} =>
               0},
         {env,
             #{{f,1} =>
                   [{type,
                        {7,8},
                        bounded_fun,
                        [{type,
                             {7,8},
                             'fun',
                             [{type,{7,8},product,[{user_type,{7,9},type,[]}]},
                              {type,{7,20},list,[{atom,{7,21},x}]}]},
                         []]}]},
             #{},#{},
             #{module => lc,records => #{},
               types =>
                   #{{type,0} =>
                         {[],
                          {remote_type,0,
                              [{atom,{5,17},erl_parse},
                               {atom,{5,27},abstract_type},
                               []]}}}},
             false,false,true,
             [{clauses_controls,true}],
             30,
             [{type,
                  {7,8},
                  bounded_fun,
                  [{type,
                       {7,8},
                       'fun',
                       [{type,{7,8},product,[{user_type,{7,9},type,[]}]},
                        {type,{7,20},list,[{atom,{7,21},x}]}]},
                   []]}]}]}}
{trace,<0.86.0>,return_from,
       {typechecker,glb_ty,4},
       {{atom,0,map},
        {constraints,#{},#{},
                     {set,0,16,16,8,80,48,
                          {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
                          {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
                            []}}}}}}
{trace,<0.86.0>,return_to,{typechecker,glb,4}}
{trace,<0.86.0>,call,
    {typechecker,glb_ty,
        [{type,0,list,
             [{user_type,
                  [{file,"erl_parse.erl"},{location,0}],
                  af_assoc_type,[]}]},
         {atom,0,any},
         #{{{type,0,list,
                [{user_type,
                     [{file,"erl_parse.erl"},{location,0}],
                     af_assoc_type,[]}]},
            {atom,0,any}} =>
               0,
           {{type,0,tuple,
                [{atom,0,type},
                 {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
                 {atom,0,map},
                 {type,0,list,
                     [{user_type,
                          [{file,"erl_parse.erl"},{location,0}],
                          af_assoc_type,[]}]}]},
            {type,0,tuple,
                [{atom,0,type},
                 {user_type,[{file,"erl_parse.erl"},{location,0}],anno,[]},
                 {atom,0,map},
                 {atom,0,any}]}} =>
               0},
         {env,
             #{{f,1} =>
                   [{type,
                        {7,8},
                        bounded_fun,
                        [{type,
                             {7,8},
                             'fun',
                             [{type,{7,8},product,[{user_type,{7,9},type,[]}]},
                              {type,{7,20},list,[{atom,{7,21},x}]}]},
                         []]}]},
             #{},#{},
             #{module => lc,records => #{},
               types =>
                   #{{type,0} =>
                         {[],
                          {remote_type,0,
                              [{atom,{5,17},erl_parse},
                               {atom,{5,27},abstract_type},
                               []]}}}},
             false,false,true,
             [{clauses_controls,true}],
             30,
             [{type,
                  {7,8},
                  bounded_fun,
                  [{type,
                       {7,8},
                       'fun',
                       [{type,{7,8},product,[{user_type,{7,9},type,[]}]},
                        {type,{7,20},list,[{atom,{7,21},x}]}]},
                   []]}]}]}}
{trace,<0.86.0>,return_from,
       {typechecker,glb_ty,4},
       {{type,0,none,[]},
        {constraints,#{},#{},
                     {set,0,16,16,8,80,48,
                          {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
                          {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
                            []}}}}}}

@erszcz erszcz changed the title Add test/known_problems/should_pass/lc_cannot_glb_different_variants.erl Add examples of list comprehension generators being none() Aug 12, 2022
@erszcz erszcz merged commit 4248daf into josefs:master Aug 22, 2022
@erszcz erszcz deleted the lc-generators-being-none branch August 24, 2022 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants