hylo-lang / hylo

The Hylo programming language

Home Page:https://www.hylo-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fatal error in `Emitter.emitConvertToForeign`

lucteo opened this issue · comments

For the following code:

type CStruct {
  var x: Int
  var y: Int
}

@ffi("some_c_initializer")
private fun some_c_initializer(_ frame: set CStruct);

public type Wrapper {

  private var base_frame: CStruct

  public init() {
    some_c_initializer(base_frame)
  }

}

we get the following error:

IR/Emitter.swift:2363: Fatal error: Unexpectedly found nil while unwrapping an Optional value

The errors stems from:

  private mutating func emitConvertToForeign(_ o: Operand, at site: SourceRange) -> Operand {
    let t = module.type(of: o)
    precondition(t.isAddress)

    let foreignConvertible = ast.core.foreignConvertible.type
    let foreignConvertibleConformance = program.conformance(
      of: t.ast, to: foreignConvertible, exposedTo: insertionScope!)!    // <---- ERROR here
    let r = ast.requirements("foreign_value", in: foreignConvertible.decl)[0]

We can certainly fix the fatal error but the actual feature we need to fill the gap in the design space here is a little complex. Dave wrote about some of the outstanding issues: https://github.com/orgs/hylo-lang/discussions/1122