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: allow unify nil with ptr[_] #128

Merged
merged 3 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions quartz/typecheck.qz
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,12 @@ fun unify(type1: Type, type2: Type): Type or error {
if type2.t_nil != nil && type1.t_optional != nil {
return type1;
}
if type1.t_nil != nil && type2.t_ptr != nil {
return type2;
}
if type2.t_nil != nil && type1.t_ptr != nil {
return type1;
}
if type1.t_any != nil {
return type2;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/cases/test24.qz
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fun main(): bool {
let p = make[ptr[i32]](1);

return p == nil;
}
1 change: 1 addition & 0 deletions tests/cases/test24.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
false
10 changes: 9 additions & 1 deletion tests/compile_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,15 @@ fn test_run() -> Result<()> {

if stdout_path.exists() {
let expected = fs::read_to_string(stdout_path)?;
let run = output.run.clone().unwrap();
let run = output.run.clone().expect(
format!(
"output.run is None.\n{}\n[COMPILE]: {}\n{}",
path.display(),
output.compile.stdout,
output.compile.stderr
)
.as_str(),
);

assert_eq!(
expected,
Expand Down