Skip to content

Implement non-null assertions #443

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

Merged
merged 2 commits into from
Jan 30, 2019
Merged

Implement non-null assertions #443

merged 2 commits into from
Jan 30, 2019

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Jan 29, 2019

Similar to #235, but implemented as another kind of assertion.

@dcodeIO dcodeIO requested a review from MaxGraey January 29, 2019 15:46
@MaxGraey
Copy link
Member

MaxGraey commented Jan 29, 2019

Is it valid?
return foo.bar!!;
arr!!![0]

NOTE
Ok, see it valid. great!

Copy link
Member

@MaxGraey MaxGraey left a comment

Choose a reason for hiding this comment

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

LGTM

@MaxGraey
Copy link
Member

How about that?:

export function testFn3(fn?: (() => Foo | null)): Foo | null {
  return fn!();
}

@dcodeIO
Copy link
Member Author

dcodeIO commented Jan 29, 2019

That fails to compile because we don't support fn?:. The following with an initializer as we require it errors for other reasons, though:

export function testFn3(fn: (() => Foo | null) | null = null): Foo | null {
  return fn!();
}
ERROR AS200: Conversion from type 'usize' to '(() => Foo | null) | null' requires an explicit cast.

Something off with assigning null to a nullable function type as it seems, but probably an issue on its own.

@MaxGraey
Copy link
Member

MaxGraey commented Jan 29, 2019

Yeah. This relate to how handle of undefined type. Because arg?: Foo produce arg: Foo | undefined. So this make sense for different PR. But first need decide if we need support this semantics and may be force it to null? Like arg?: Fooshould be same as arg: Foo | null = null

@dcodeIO
Copy link
Member Author

dcodeIO commented Jan 29, 2019

Leads us to nullable basic types as well then, like a?: i32. Might be too early to decide.

@MaxGraey
Copy link
Member

MaxGraey commented Jan 29, 2019

Same as a: i32 | null. Currently this valid but not handle properly. I suggest use a?: Ref as short alias for a: Ref | null = null and a?: i32 as a: i32 = 0. WDYT?

@MaxGraey
Copy link
Member

Also found problem with Foo | null | null which valid on TS but currently fail in AS

@dcodeIO
Copy link
Member Author

dcodeIO commented Jan 29, 2019

Yeah, i32 | null should emit at least a warning. Can take a look at that later.

@MaxGraey
Copy link
Member

But may be Foo | null | null issue better fix in separate PR.

@dcodeIO dcodeIO merged commit d843772 into master Jan 30, 2019
@dcodeIO dcodeIO deleted the non-null-assertion branch March 7, 2019 23:48
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