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

Call to Void->Void property does not compile #5519

Closed
RealyUniqueName opened this issue Aug 14, 2016 · 3 comments
Closed

Call to Void->Void property does not compile #5519

RealyUniqueName opened this issue Aug 14, 2016 · 3 comments

Comments

@RealyUniqueName
Copy link
Member

RealyUniqueName commented Aug 14, 2016

Following sample compiles and works fine with 3.2.1, but fails to compile with latest 3.3

class Test {
  var callbackProperty : Void->Void;

  static function main() {
    var t = new Test();
    trace(t.callbackProperty());
  }

  function new () {}
}

Compilation error:

Test.hx:6: characters 10-30 : Cannot use Void as value

Same error for static callback properties.

try-haxe 3.3
try-haxe 3.2.1

@Simn
Copy link
Member

Simn commented Aug 14, 2016

That's intended, you're trying to use the result of a Void-returning function as a value which is not a good idea.

@Simn Simn closed this as completed Aug 14, 2016
@MSGhero
Copy link

MSGhero commented Aug 19, 2016

@Simn If Void can't be used as a value, then what's going on here?

class Test {

    static function main() {
        var g = new A<Void>();
        g.test(null);
        g.test2(voidVoid); // Void -> Void should be (Void) -> Unknown<0> For function argument 'f'
        // g.test2(cast voidVoid); // compiles and runs
    }

    static function voidVoid():Void { }
}

class A<T> {
    var t:T;
    public function new() { }
    public function test(t:T):Void { this.t = t; }
    public function test2<U>(f:T->U):Void { f(t); }
}

I got OP's error because my <T> happens to be Void in one case, and I tried to use that as an input to voidVoid. But I can still use Void/null as a value for g.test(null).

@nadako
Copy link
Member

nadako commented Aug 19, 2016

But I can still use Void/null as a value for g.test(null).

no more on 3.3/git

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

No branches or pull requests

4 participants