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

Type param Void #3463

Open
andyli opened this issue Oct 10, 2014 · 12 comments · May be fixed by #11558
Open

Type param Void #3463

andyli opened this issue Oct 10, 2014 · 12 comments · May be fixed by #11558
Milestone

Comments

@andyli
Copy link
Member

andyli commented Oct 10, 2014

The following fails to be compiled, but I would expect one of the lines of ones or twos is valid.

class Test{
    static function main():Void {
        var voids:Array<Void> = [null, null, null];
        var ones = voids.map(function() return 1);  //Void -> Void should be (Void) -> Unknown<0>
        var twos = voids.map(function(v) return 2); //Arguments and variables of type Void are not allowed
    }
}
@ncannasse
Copy link
Member

Array of Void does not make sense in the first place. Maybe we should actually forbid Void in type parameters unless @:generic ?

@Simn
Copy link
Member

Simn commented Oct 10, 2014

I think people like to use it for Signals or something.

@Simn
Copy link
Member

Simn commented Oct 10, 2014

But that's probably only Void -> Void or Something -> Void. I don't think using plain Void as a type parameter makes sense either.

@andyli
Copy link
Member Author

andyli commented Oct 10, 2014

As Simn mentioned, I was using it for Signals and promhx, to denote an event without any event data.
Some other time I use it with map as poor man's set:

var intset = new Map<Int, Void>();
intset.set(3, null);
trace(intset.exists(3)); //true

Anyway my use case is to have a type that accepts nothing but null. I could have used tink's Noise, but it sound strange to me to have more than one value to denote nothingness.

@Atry
Copy link
Contributor

Atry commented Dec 1, 2014

I think we should allow parameters of Null<Void>, for example:

class Nv
{
    static function main()
    {
        foo(null);
    }
    static function foo(nv:Null<Void>):Void
    {
    }
}

@Simn
Copy link
Member

Simn commented Dec 11, 2014

There's something about the Null<Void> idea that I like, but I'm not sure.

@Simn
Copy link
Member

Simn commented Jan 15, 2015

Another option would be to give some semantics to _ as a variable identifier and ignore the error in that case.

@Atry
Copy link
Contributor

Atry commented Feb 22, 2015

#3884

@Simn Simn added this to the 3.3 milestone Feb 22, 2015
@Simn Simn modified the milestones: 3.4, 3.3.0-rc1 Mar 1, 2016
@Simn Simn modified the milestones: 3.4, 4.0 Jan 9, 2017
@Simn Simn modified the milestones: Release 4.0, Design Apr 17, 2018
@Simn
Copy link
Member

Simn commented Mar 2, 2020

Something like this crashes the JVM generator with an EmptyStack exception:

interface I<T> {
	public function test():T;
}

class Main implements I<Void> {
	static function main() {}

	public function test() {}
}

I don't think such a thing should be allowed.

@kevinresol
Copy link
Contributor

Please, forbid applying Void as type parameter.

@EliteMasterEric
Copy link
Contributor

I would like to see some way to gracefully handle Void as a type parameter.

If I have a callback handler that takes T->Void, and I want to make a callback with no argument, I would set T to Void->Void, but that confuses the compiler because there's no argument that satisfies dispatch(value:T).

@kevinresol
Copy link
Contributor

IMO, the Void -> Void notation is just an illusion that one can apply T = Void to T -> Void and make it () -> Void. I still vote for disallowing a plain Void being used as type param...

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

Successfully merging a pull request may close this issue.

6 participants