RealyUniqueName / Safety

Null safety for Haxe
MIT License
54 stars 5 forks source link

Proposal: show nullable error before function inlining #9

Closed restorer closed 5 years ago

restorer commented 5 years ago
class IntHolder {
    public var v : Int;

    public function new(v : Int) {
        this.v = v;
    }

    public inline function inlineCopy() : IntHolder {
        return new IntHolder(v);
    }
}

class MaybeBug4 {
    public function bug() : Void {
        var h : Null<IntHolder> = ((Math.random() > 0.5) ? new IntHolder(42) : null);

        // Is it possible to show `Safety: Cannot access "inlineCopy" of a nullable value.`
        // instead of `Safety: Cannot access "v" of a nullable value.`?
        function cb() : IntHolder { return h.inlineCopy(); }
    }
}

See https://github.com/restorer/haxe-safety-bugs/blob/master/safetybugs/Main.hx#L71 for working example.

restorer commented 5 years ago

This is for Haxe 4.0.0-preview.5 and Safety from master.

RealyUniqueName commented 5 years ago

Unfortunately, inlining happens before the plugin could access typed syntax tree. I'm leaving this open for more research. Maybe I could find a workaround.

RealyUniqueName commented 5 years ago

So after talking to core dev I got an answer it's not possible at the moment.