Problem with bit syntax compilation

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with bit syntax compilation

Jouni Rynö-2
>From the following code

-module(test).

error(Test) ->
    if
        Test == 1 ->
            Problem = 1;
        Test == 2 ->
            Problem = 2
    end,
    Dummy = 1,
    OKbin = <<Test:7, Dummy:9>>,    % used only to prove, that it works
normally
    MyBin = [<<Test:7, Problem:9>>, OKbin].

I get compilation error from erlc test.erl (eshell V5.0.2


/proj/cosima/egse/test.erl:none: internal error in v3_codegen;
crash reason: {{case_clause,{'EXIT',{function_clause,
                                        [{v3_codegen,fetch_reg,['Problem
',[]]},
                                         {v3_codegen,'-saves/3-fun-0-',3
},
                                         {lists,map,2},
                                         {v3_codegen,adjust_stack,4},
                                         {v3_codegen,match_cg,6},
                                         {v3_codegen,'-cg_list/5-fun-0-'
,3},
                                         {v3_codegen,flatmapfoldl,3},
                                         {v3_codegen,cg_list,5}|
                                         more]}}},
               [{compile,'-select_passes/2-fun-2-',2},
                {compile,'-internal_comp/4-fun-1-',2},
                {compile,fold_comp,3},
                {compile,internal_comp,4},
                {compile,internal,3}]}


Any way to circumvent this ?

With regards
        Jouni


  Jouni Ryn?                            mailto://Jouni.Ryno/
                                        http://www.geo.fmi.fi/~ryno/
  Finnish Meteorological Institute      http://www.fmi.fi/
  Geophysical Research                  http://www.geo.fmi.fi/
  P.O.BOX 503                           Tel      (+358)-9-19294656
  FIN-00101 Helsinki                    FAX      (+358)-9-19294603
  Finland                               priv-GSM (+358)-50-5302903
 
  "It's just zeros and ones, it cannot be hard"






Reply | Threaded
Open this post in threaded view
|

Problem with bit syntax compilation

Daniel Neri
"Jouni Ryno" <jouni.ryno> writes:

> error(Test) ->
>     if
> Test == 1 ->
>    Problem = 1;
> Test == 2 ->
>    Problem = 2
>     end,
>     Dummy = 1,
>     OKbin = <<Test:7, Dummy:9>>,    % used only to prove, that it works
> normally
>     MyBin = [<<Test:7, Problem:9>>, OKbin].
>
> I get compilation error from erlc test.erl (eshell V5.0.2

Although it does look like a bug, you missed the warning:

  /tmp/test.erl:12: Warning: variable 'Problem' exported from 'if' (line 4)

So instead try:

   ,----
   | error(Test) ->
   |     Problem = if
   |                   Test == 1 ->
   |                       1;
   |                   Test == 2 ->
   |                       2
   |               end,
   |     Dummy = 1,
   |     OKbin = <<Test:7, Dummy:9>>,
   |     MyBin = [<<Test:7, Problem:9>>, OKbin].
   `----


Regards,
   --Daniel

--
Daniel Neri
dne


Reply | Threaded
Open this post in threaded view
|

Problem with bit syntax compilation

Jouni Rynö-2
> "Jouni Ryno" <jouni.ryno> writes:
>
> > error(Test) ->
> >     if
> > Test == 1 ->
> >    Problem = 1;
> > Test == 2 ->
> >    Problem = 2
> >     end,
> >     Dummy = 1,
> >     OKbin = <<Test:7, Dummy:9>>,    % used only to prove, that it works
> > normally
> >     MyBin = [<<Test:7, Problem:9>>, OKbin].
> >
> > I get compilation error from erlc test.erl (eshell V5.0.2
>
> Although it does look like a bug, you missed the warning:
>
>   /tmp/test.erl:12: Warning: variable 'Problem' exported from 'if' (line 4)
>
I do NOT get the warning ! Hmm, do you get the warning, if you add the
fallback
true ->
        Problem = 3 % default

??

But the following does make it work, even in my real life case !
Thanks !

> So instead try:
>
>    ,----
>    | error(Test) ->
>    |     Problem = if
>    |                   Test == 1 ->
>    |                       1;
>    |                   Test == 2 ->
>    |                       2
>    |               end,
>    |     Dummy = 1,
>    |     OKbin = <<Test:7, Dummy:9>>,
>    |     MyBin = [<<Test:7, Problem:9>>, OKbin].
>    `----
>
>
> Regards,
>    --Daniel
>
> --
> Daniel Neri
> dne



  Jouni Ryn?                            mailto://Jouni.Ryno/
                                        http://www.geo.fmi.fi/~ryno/
  Finnish Meteorological Institute      http://www.fmi.fi/
  Geophysical Research                  http://www.geo.fmi.fi/
  P.O.BOX 503                           Tel      (+358)-9-19294656
  FIN-00101 Helsinki                    FAX      (+358)-9-19294603
  Finland                               priv-GSM (+358)-50-5302903
 
  "It's just zeros and ones, it cannot be hard"






Reply | Threaded
Open this post in threaded view
|

Problem with bit syntax compilation

Robert Virding-4
In reply to this post by Jouni Rynö-2
"Jouni Ryno" <jouni.ryno> writes:

>From the following code
>
>-module(test).
>
>error(Test) ->
>    if
> Test == 1 ->
>    Problem = 1;
> Test == 2 ->
>    Problem = 2
>    end,
>    Dummy = 1,
>    OKbin = <<Test:7, Dummy:9>>,    % used only to prove, that it works
>normally
>    MyBin = [<<Test:7, Problem:9>>, OKbin].
>
>I get compilation error from erlc test.erl (eshell V5.0.2
>
>/proj/cosima/egse/test.erl:none: internal error in v3_codegen;
>crash reason: {{case_clause,{'EXIT',{function_clause,
>                                        [{v3_codegen,fetch_reg,['Problem
> ...

This is a compiler bug which has been fixed in the next release.  The
way around it is as someone already has shown.  The warning should be
printed AFTER the compiler error trace.

        Robert

--
Robert Virding                          Tel: +46 (0)8 545 55 017
Alteon Web Systems                      Email: rv
S:t Eriksgatan 44                       WWW: http://www.bluetail.com/~rv
SE-112 34 Stockholm, SWEDEN
"Folk s?ger att jag inte bryr mig om n?gonting, men det skiter jag i".