erlc question, why no error message for erronous code?

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

erlc question, why no error message for erronous code?

Bengt Kleberg-3
greetings,

i had a (runtime) crash with ''badarith''. the code was:
rate_class + 1

while not beeing a compiler writer, i somehow think it would be
possible for the compiler to diagnose this kind of error*, would it
not?

*i belive this is a ''attempt to do arithmetic on an atom'' kind of error.


bengt



Reply | Threaded
Open this post in threaded view
|

erlc question, why no error message for erronous code?

Joe Williams-2

But it's not an error.

  catch (rate_class + 1)

is well defined

Now why anybody might want to write that is a mystery - but it it allowed

(A warning might be better  - oh and a pragma to turn off the warning)
then you could write

   X = catch ( (yesIknowItlooksFunny) rate_class + 1)

Many years ago I was programming some hardware - I wanted to send
an illegal command to the hardware.

The software would not allow this. I asked the compiler writer why I could not
send a op code 23 to the hardware - he said "you can't it's illegal"

  I said  - "but I want  to test the hardware  - see if  the red light
goes on when you send it an illegal command"

  He said, "you can't send an illegal command to the hardware"

  So I had to /dev/null his compiler and re-write the thing so I could do
what I wanted.

So from then on I was of the opinion that a compiler should allow anything
even if it looks silly *provided* it is well-defined and safe.

and thus it was :-)

/Joe


On Tue, 3 Jun 2003, Bengt Kleberg wrote:

> greetings,
>
> i had a (runtime) crash with ''badarith''. the code was:
> rate_class + 1
>
> while not beeing a compiler writer, i somehow think it would be
> possible for the compiler to diagnose this kind of error*, would it
> not?
>
> *i belive this is a ''attempt to do arithmetic on an atom'' kind of error.
>
>
> bengt
>



Reply | Threaded
Open this post in threaded view
|

erlc question, why no error message for erronous code?

Chris Pressey
On Tue, 3 Jun 2003 13:15:33 +0200 (CEST)
Joe Armstrong <joe> wrote:

> [...]
> Many years ago I was programming some hardware - I wanted to send
> an illegal command to the hardware.
>
> The software would not allow this. I asked the compiler writer why I could not
> send a op code 23 to the hardware - he said "you can't it's illegal"
>
>   I said  - "but I want  to test the hardware  - see if  the red light
> goes on when you send it an illegal command"
>
>   He said, "you can't send an illegal command to the hardware"

Perfect place for a compile-time warning, though...

warning: line 123: this code is fubar, but hey, you're the boss!

-Chris


Reply | Threaded
Open this post in threaded view
|

erlc question, why no error message for erronous code?

Björn Gustavsson-3
In reply to this post by Bengt Kleberg-3
We plan have add warnings of this kind in the R10 release.

/Bjorn

Bengt Kleberg <eleberg> writes:

> greetings,
>
> i had a (runtime) crash with ''badarith''. the code was:
> rate_class + 1
>
> while not beeing a compiler writer, i somehow think it would be
> possible for the compiler to diagnose this kind of error*, would it
> not?
>
> *i belive this is a ''attempt to do arithmetic on an atom'' kind of error.
>
>
> bengt
>

--
Bj?rn Gustavsson            Ericsson Utvecklings AB
bjorn      ?T2/UAB/F/P
                            BOX 1505
+46 8 727 56 87    125 25 ?lvsj?