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

Add support for the polymorphic this type #41

Merged
merged 3 commits into from Oct 10, 2017

Conversation

Projects
None yet
2 participants
@exoego
Copy link
Contributor

exoego commented Oct 10, 2017

Converts TypeScript's the polymorphic this type to Scala's this.type.
The polymorphic this type is useful to express hierarchical fluent interfaces easily.

Use cases

@sjrd

This comment has been minimized.

Copy link
Owner

sjrd commented Oct 10, 2017

Unfortunately, TypeScript's this type does not correspond to Scala's this type, as can be seen in this example. In Scala, the last two lines would not typecheck. But they do in TypeScript.

@sjrd

This comment has been minimized.

Copy link
Owner

sjrd commented Oct 10, 2017

Hum well, actually it's not like the TypeScript importer is sound anyway, so I guess this would work more often than not.

Could you please rebase this branch on top of master, so that only relevant commits are displayed in the commit list of this PR?

@exoego exoego force-pushed the exoego:support-polymorphic-this branch 2 times, most recently from 04c4201 to a44f401 Oct 10, 2017

@exoego

This comment has been minimized.

Copy link
Contributor Author

exoego commented Oct 10, 2017

@sjrd I rebased this branch to show only relevant commits.

so I guess this would work more often than not.

Thanks!! I hope so too.

@@ -299,6 +299,9 @@ object TypeRef {
val Unit = TypeRef(scala dot Name("Unit"))
val Null = TypeRef(scala dot Name("Null"))
val Nothing = TypeRef(scala dot Name("Nothing"))
val ThisType = TypeRef(new Name("this.type") {
override def toString(): String = "this.type"
})

This comment has been minimized.

@sjrd

sjrd Oct 10, 2017

Owner

That's nonsensical. this.type is not the selection of a member type on the type this.

It would make more sense to represent this.type as a Singleton(QualifiedName(Name.THIS)), where THIS is something like Name("<this>"). It is then the responsibility of the printer to handle this case.

This comment has been minimized.

@exoego

exoego Oct 10, 2017

Author Contributor

@sjrd Done!

@exoego exoego force-pushed the exoego:support-polymorphic-this branch 2 times, most recently from bb59f1b to 5d5e50d Oct 10, 2017

exoego
Change a representation of `this.type` since it is not a selection of…
… a member `type` of `this`. The responsibility of handling this case is moved to Printer.

@exoego exoego force-pushed the exoego:support-polymorphic-this branch from 5d5e50d to 5910041 Oct 10, 2017

@sjrd

sjrd approved these changes Oct 10, 2017

Copy link
Owner

sjrd left a comment

Thanks.

@sjrd sjrd changed the title Add support of polymorphic this type Add support for the polymorphic this type Oct 10, 2017

@sjrd sjrd merged commit fbc4f20 into sjrd:master Oct 10, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@exoego exoego deleted the exoego:support-polymorphic-this branch Nov 14, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment