librasteve / raku-Physics-Measure

do calculations on objects with value, units and error
Artistic License 2.0
11 stars 2 forks source link

Better errors for undefined #26

Closed wayland closed 3 years ago

wayland commented 3 years ago

The error coming from the following would be more useful if it were to complain about the undefined value in some way; what I really want is a documented way to test if it's undefined like this. For the record, calling defined($!height) inside foo() also fails.

#!/usr/bin/raku

use     Physics::Unit;
use     Physics::Measure;

class   Test {
        has Length $.length;
        has Length $.width;

        method  foo {
                say $!length <=> $!width;
        }
}

my $a = Test.new();

$a.foo();

HTH,

librasteve commented 3 years ago

hi @wayland - I tried this... with no Physics::Unit or Physics::Measure...

!/usr/bin/raku

use Physics::Unit;

use Physics::Measure;

class Test { has Real $.length; has Real $.width; method foo { say $!length <=> $!width; }
} my $a = Test.new();

$a.foo();

It gives this error: Invocant of method 'Bridge' must be an object instance of type 'Real', not a type object of type 'Real'. Did you forget a '.new'?

So I am wondering whether is this a general raku issue - you are comparing 2 undefined objects after all.

I kinda prefer my error ... Cannot look up attributes in a Physics::Measure::Length type object

What specifically would you propose?

~p6steve