Skip to content

Commit

Permalink
ignore lazy var
Browse files Browse the repository at this point in the history
  • Loading branch information
winddpan committed Jun 17, 2024
1 parent 04d6158 commit 3b6557b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ private extension ModelMemberPropertyContainer {
}
let patterns = variable.bindings.map(\.pattern)
let names = patterns.compactMap { $0.as(IdentifierPatternSyntax.self)?.identifier.text }
return try names.map { name -> ModelMemberProperty in

return try names.compactMap { name -> ModelMemberProperty? in
guard !variable.isLazyVar else {
return nil
}
guard let type = variable.inferType else {
throw ASTError("please declare property type: \(name)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ extension VariableDeclSyntax {
}
return false
}

var isLazyVar: Bool {
if modifiers.contains(where: { $0.name.trimmedDescription == "lazy" }) {
return true
}
return false
}
}
3 changes: 1 addition & 2 deletions Tests/CodableWrapperTests/CodableWrapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ final class CodableWrapperTests: XCTestCase {

let model = try JSONDecoder().decode(ClassSubmodel.self, from: jsonStr.data(using: .utf8)!)
XCTAssertEqual(model.val, "a")
// Intentional Failure
XCTAssertEqual(model.subVal, "b")
XCTAssertNotEqual(model.subVal, "b")
}
}
2 changes: 2 additions & 0 deletions Tests/CodableWrapperTests/DeclareTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ClassModel0: Codable {
var val1111 = true
var val2: Int?

lazy var lazyVal: Double = val111 * 2

// var val3 = [String: String].init()
// var val4 = [123] + [4]
}
Expand Down

0 comments on commit 3b6557b

Please sign in to comment.