Skip to content

Commit

Permalink
Insert init directive for empty product type
Browse files Browse the repository at this point in the history
Fixes: #997
  • Loading branch information
WalterSmuts committed Sep 17, 2023
1 parent 7c7f7be commit d22f334
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Sources/IR/Emitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ struct Emitter {
insertionPoint = .end(of: entry)
let bodyFrame = Frame(locals: locals)
let returnSite = pushing(bodyFrame, { $0.lowerStatements($0.ast[d].body!, expecting: .void) })

let receiverLayout = AbstractTypeLayout(of: program[d].receiver.type, definedIn: program)

// If the object is empty, simply mark it initialized.
if receiverLayout.properties.isEmpty {
let receiver = entry.parameter(0)
insert(module.makeMarkState(receiver, initialized: true, at: ast[d].site))
}
insert(module.makeReturn(at: returnSite))
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/HyloTests/TestCases/Lowering/EmptyStruct.hylo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//- lowerToFinishedIR expecting: failure
//- lowerToFinishedIR expecting: success

public type Foo {
public init() { } //! diagnostic set parameter not initialized before function returns
public init() { }
}

0 comments on commit d22f334

Please sign in to comment.