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

Implement New object definition #175

Conversation

NeilKleistGao
Copy link
Member

Related Issues:

In this PR:

  • Only generate fields for vals rather than lets
    • If a let binding is used in a method, we still generate a private field
  • Only generate public getters for constructor parameters with vals
    • If it is in constructor(...) and has no val, the parameter is available only in the constructor
    • Add static function $unapply to non-plain classes(i.e., class ClassName(...))
    • Unfold let-bindings generated by UCS for $unapply method invocations
  • Fix Code generation encountered an error: unresolved symbol if members only have type signatures
  • Add virtual keyword for funs and vals.
    • If a member only has the type signature, it is virtual automatically
    • Require this when accessing the virtual members
    • Overriding non-virtual members is not allowed
  • Add restrictions on constructors
    • Using this is forbidden in the constructor statements and RHS of vals, including directly and indirectly
    • Accessing non-virtual members via this is still allowed if the members do not refer to this

@LPTK
Copy link
Contributor

LPTK commented Sep 16, 2023

I think a good test to add would be this:

abstract class Foo: Int -> Int {
  val x = f
  fun f = this(0)
}
//│ ╔══[ERROR] Cannot access `this` while initializing field x
//│ ║  l.6: 	  val x = f
//│ ║       	      ^^^^^
//│ ╟── The access to `this` is here
//│ ║  l.7: 	  fun f = this(0)
//│ ╙──     	          ^^^^
//│ abstract class Foo: Int -> Int {
//│   fun f: nothing
//│   let x: nothing
//│ }

Since it accesses this in an unusual way!

shared/src/main/scala/mlscript/helpers.scala Outdated Show resolved Hide resolved
shared/src/main/scala/mlscript/Typer.scala Outdated Show resolved Hide resolved
Copy link
Contributor

@LPTK LPTK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I'm happy enough with the changes now!

@LPTK
Copy link
Contributor

LPTK commented Sep 17, 2023

@NeilKleistGao please fix the conflicts and close the remaining conversations, then please merge (with a merge commit).

@NeilKleistGao NeilKleistGao merged commit fd2215a into hkust-taco:new-definition-typing Sep 18, 2023
1 check passed
@LPTK LPTK deleted the new-object-definition branch September 18, 2023 09:18
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 this pull request may close these issues.

2 participants