Open RyanLeber opened 10 months ago
When using the builtin hash function on a String the returned hash value is not deterministic unless the lifetime of the string is extended.
String
fn main(): let s1: String = "mojo" print("s1: ", hash(s1._as_ptr(), len(s1))) print("s1: ", hash(s1._as_ptr(), len(s1)))
s1: 1974758210704828359 s1: 7376120937799554262
Lifetime extended:
fn main(): let s1: String = "mojo" print("s1: ", hash(s1._as_ptr(), len(s1))) print("s1: ", hash(s1._as_ptr(), len(s1))) _ = s1
s1: 1974758210704828359 s1: 1974758210704828359
- Ubuntu 22.04.3 LTS (WSL 2) - mojo 0.6.1 (876ded2e) - modular 0.3.1 (589ce200)
FYI @bethebunny
Bug description
When using the builtin hash function on a
String
the returned hash value is not deterministic unless the lifetime of the string is extended.Lifetime extended:
Steps to reproduce
System information