Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty struct init alternate #1016

Merged
merged 2 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 5 additions & 0 deletions Tests/HyloTests/TestCases/Lowering/EmptyStruct.hylo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//- lowerToFinishedIR expecting: success

public type Foo {
public init() { }
}