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

fix: introduce null type to support resolver null expression #2663

Closed
wants to merge 5 commits into from

Conversation

HerrCai0907
Copy link
Member

fix: #2662

The idea is compiler should infer the left type according to right type before compiling it.

@dcodeIO
Copy link
Member

dcodeIO commented Mar 4, 2023

A more comprehensive fix for such cases could be, now that we have AnyClass <: Object, to compile null as Object instead of usize if there isn't a more specific context. Haven't tried, but if this works we'd also get rid of the "compiles to unusual type" warning.

@HerrCai0907
Copy link
Member Author

@dcodeIO It is a break change, see this test code.
Of course, maybe we can do it, I do not think it is a good idea to make null as <usize>0. it just likes nullptr in cpp and NULL in c.

{ // only nulls infers as usize[]
  let arr1 = [null];
  assert(isInteger(arr1[0]));
  assert(!isNullable(arr1[0]));
  let arr2 = [null, null];
  assert(isInteger(arr2[0]));
  assert(!isNullable(arr2[0]));
}
{ // null in integer contexts infers as usize
  let arr1 = [1, null];
  assert(isInteger(arr1[0]));
  assert(!isNullable(arr1[0]));
  let arr2 = [null, 1];
  assert(isInteger(arr2[0]));
  assert(!isNullable(arr2[0]));
}

@HerrCai0907
Copy link
Member Author

HerrCai0907 commented Mar 4, 2023

After trying it, null should not be ~lib/object/Object, consider this case, [null, "str"] should be inferred as Array<string | null>, but [nullable object, "str"] should be inferred as Array<object | null>

@HerrCai0907 HerrCai0907 changed the title fix: introduce resolver type before compiling a not eq expresssion fix: introduce null type to support resolver null expression Mar 6, 2023
Copy link
Member

@CountBleck CountBleck left a comment

Choose a reason for hiding this comment

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

I can't say anything meaningful about big changes to the type system.

@HerrCai0907 HerrCai0907 closed this Oct 7, 2023
@HerrCai0907 HerrCai0907 deleted the fix/null-infer branch October 7, 2023 01:38
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.

Could not compare null with nullable type
3 participants