You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A method declared for one instantiation (impl Box[str]) is callable on another (Box[isize]): safe code reads an integer as text #3508
Found while moving List.join into the standard library (#3483): declared as impl List[str], it was accepted on a List[i32].
type Box[T] { v: T }
impl Box[str]:
fn shout() -> str: self.v.to_upper()
fn main:
let a = Box { v: "hi" }
print(a.shout())
let b = Box { v: 7 }
print(b.shout()) // accepted; reads the integer as a str
Installed compiler (main at #3507): compiles with no error, prints HI and then an empty line. No unsafe anywhere.
Expected:b.shout() is refused: shout is declared for Box[str], and b is a Box[isize].
Why it matters: this is a memory-safety hole in safe code (the method body reads the receiver's payload at the wrong type), and it blocks declaring any built-in that exists for one element type only (List[str].join).
Activity
A method declared for one instantiation is refused on another; it was…
List.join is declared in the standard library for List[str] and its b…