hylo-lang / hylo

The Hylo programming language
https://www.hylo-lang.org
Apache License 2.0
1.24k stars 58 forks source link

Core/TypedProgram.swift:118: Fatal error: Unexpectedly found nil while unwrapping an Optional value #693

Closed dabrahams closed 7 months ago

dabrahams commented 1 year ago

Compile this:

public trait Equatable {

  fun infix== (_ other: Self) -> Bool

}

extension Equatable {
  public fun infix!=  (_ other: Self) -> Bool { !(self == other) }
}
dabrahams commented 1 year ago

@kyouko-taiga Seems to work; I think we can close this?

kyouko-taiga commented 1 year ago

Oh wow. I didn't expect monomorphization would be able to pick up definitions in extensions. We can close if we have a test that runs this code.

peter-evans commented 8 months ago

Would this be ok as a suitable end-to-end test? If so, what would be a good filename to describe this test?

I've checked it compiles and runs.

//- compileAndRun expecting: success

public trait Equatable {

  fun infix== (_ other: Self) -> Bool

}

extension Equatable {
  public fun infix!= (_ other: Self) -> Bool { !(self == other) }
}

type A: Deinitializable, Equatable {
  public let x: Int
  public memberwise init
  fun infix== (_ other: Self) -> Bool { self.x == other.x }
}

public fun main() {
  let a = A(x: 1)
  let b = A(x: 1)
  let c = A(x: 2)
  precondition(a == b)
  precondition(a != c)
  precondition(b != c)
}