hash-org / hashc

The Hash programming language compiler :zap:
https://hash-org.github.io/hashc/
MIT License
26 stars 2 forks source link

Fix string comparison code generation #1075

Closed feds01 closed 3 months ago

feds01 commented 3 months ago

Description

This patch fixes a bug with code generation not generating the required code for string comparisons in some cases. This resulted into odd behaviour when writing code like:

foo := () => "hello"

main := () => {
  if "hello" == foo() {
     println("yes!")
  }
}

The existing implementation tried to compare by ptr which inevitably failed due to the strs having different base addresses. Hence, in the above example, `yes! would not be printed.

This now properly invokes str_eq in all string comparison cases, and ensures that string comparisons behave as expected.

Commits