Skip to content

Better support for @:signal #43

@gene-pavlovsky

Description

@gene-pavlovsky

Using tink_lang 0.6.4, the below code compiles but doesn't work as expected.
The constructor generated by tink_lang takes event from the constructor param, and creates a new _event signal trigger, because of the partial implementation in the interface.

With tink_lang 0.7.0, the below code doesn't compile (which is better than compiling to code that doesn't behave as expected).

If not too tricky, it would be nice if the generated code would take the _event signal trigger from the constructor param, and init the event from it, as normally happens when using the @:signal syntax.

package;

using tink.CoreApi;

class Test {
	static function main() {
		final trigger:SignalTrigger<Noise> = Signal.trigger();
		trigger.asSignal().handle(_ -> trace("Mischief managed"));
		new Emitter(trigger).emit();
	}
}

@:tink class Emitter implements IEmitter {
	//*
	@:signal var event:Noise = _;
	/*/
	public var _event:SignalTrigger<Noise> = _;
	public var event(get, null):Signal<Noise>;
		inline function get_event() return _event.asSignal();
	//*/

	public function emit() _event.trigger(Noise);
}

@:tink interface IEmitter {
	@:signal var event:Noise;
}
// build.hxml
-D no-deprecation-warnings

-lib tink_core
-lib tink_lang

-cp src
-main Test

-js bin/test.js

--cmd node bin/test.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions