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

Optional args #183

Draft
wants to merge 40 commits into
base: new-definition-typing
Choose a base branch
from

Conversation

mbroughani81
Copy link
Contributor

No description provided.

@mbroughani81 mbroughani81 marked this pull request as ready for review September 28, 2023 08:52
@mbroughani81 mbroughani81 marked this pull request as draft September 28, 2023 08:53
@mbroughani81 mbroughani81 reopened this Sep 28, 2023
@LPTK
Copy link
Contributor

LPTK commented Sep 28, 2023

It seems that the branch you merged earlier was still a wildly outdated version. That's why it would help you to use a git GUI, which would allow you to better visualize what you're doing.

@mbroughani81
Copy link
Contributor Author

mbroughani81 commented Sep 29, 2023

It seems that the branch you merged earlier was still a wildly outdated version. That's why it would help you to use a git GUI, which would allow you to better visualize what you're doing.

I will give it a try!
BTW, I resolved the conflict. Almost all was because of the FldFlags new fields.

@LPTK
Copy link
Contributor

LPTK commented Sep 29, 2023

You messed up the merge a bit. File QML_exist_Classes_CT.mls was deleted from the main branch and you mistakenly reinstated it.

@LPTK
Copy link
Contributor

LPTK commented Sep 29, 2023

Test cases to add

As discussed on Discord, here are expected usages of optional parameters:

fun foo0(x: Int?) = if x is undefined then 0 else x + 1

fun foo1(x?) = if x is undefined then 0 else x + 1

The following should not type check

:e
fun foo0(x: Int?) = x + 1

:e
fun foo1(x?) = x + 1

To do this, you have to adapt the typing of tuples when in pattern positions.

And some interesting cases to add, which contain signature checks:

fun foo: (x: Int?) -> Int
fun foo(x?) = if x is undefined then 0 else x + 1

// Ok: function with optional parameter can be widened to function with mandatory parameter
fun foo: (x: Int) -> Int
fun foo(x?) = if x is undefined then 0 else x + 1

:e // The definition's parameter spec is too strong
fun foo: (x: Int?) -> Int
fun foo(x) = x + 1

And some subtype tests:

fun f(x) = (x : [Int, Int?]) : ['a, 'b]

I expect we could accept the case above by constraining Int | undefined <: 'b

@noordahx noordahx mentioned this pull request Apr 22, 2024
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