Skip to content

Commit

Permalink
Address CI feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Adora Lynch committed Nov 27, 2024
1 parent 804971d commit 3c1cafa
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 65 deletions.
6 changes: 3 additions & 3 deletions Sources/Yams/AliasDereferencingStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import Foundation

public protocol AliasDereferencingStrategy: AnyObject {

subscript(_ key: Anchor) -> Any? { get set }
}

public class BasicAliasDereferencingStrategy: AliasDereferencingStrategy {
public init() {}

private var map: [Anchor: Any] = .init()

public subscript(_ key: Anchor) -> Any? {
get { map[key] }
set { map[key] = newValue }
Expand Down
1 change: 1 addition & 0 deletions Sources/Yams/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

add_library(Yams
AliasDereferencingStrategy.swift
Anchor.swift
Constructor.swift
Decoder.swift
Expand Down
41 changes: 20 additions & 21 deletions Sources/Yams/Decoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ public class YAMLDecoder {
self.encoding = encoding
self.aliasDereferencingStrategy = aliasDereferencingStrategy
}

/// Encoding
public var encoding: Parser.Encoding = .default

/// Alias dereferencing strategy to use when decoding. Defaults to nil
public var aliasDereferencingStrategy: AliasDereferencingStrategy?

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 26 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope
}

/// Options to use when decoding from YAML.
public var options = Options()

/// Creates a `YAMLDecoder` instance.
///
/// - parameter encoding: String encoding,
public convenience init(encoding: Parser.Encoding) {
self.init()
self.options.encoding = encoding
}

/// Creates a `YAMLDecoder` instance.
public init() {}

Expand All @@ -56,7 +56,7 @@ public class YAMLDecoder {
if let dealiasingStrategy = options.aliasDereferencingStrategy {
finalUserInfo[.aliasDereferencingStrategy] = dealiasingStrategy

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'

Check failure on line 57 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

type 'CodingUserInfoKey' has no member 'aliasDereferencingStrategy'
}

let decoder = _Decoder(referencing: node, userInfo: finalUserInfo)
let container = try decoder.singleValueContainer()
return try container.decode(type)
Expand Down Expand Up @@ -334,26 +334,26 @@ extension _Decoder: SingleValueDecodingContainer {
if let dereferenced = dereferenceAnchor(type) {
return dereferenced
}

let constructed = try _construct(type)

recordAnchor(constructed)

return constructed
}

private func _construct<T: Decodable>(_ type: T.Type) throws -> T {
if let constructibleType = type as? ScalarConstructible.Type {
let scalarConstructed = try constructScalar(constructibleType)
guard let t = scalarConstructed as? T else {
guard let scalarT = scalarConstructed as? T else {
throw _typeMismatch(at: codingPath, expectation: type, reality: scalarConstructed)
}
return t
return scalarT
}
// not scalar constructable, initialize as Decodable
return try type.init(from: self)
}

/// constuct `T` from `node`
private func constructScalar<T: ScalarConstructible>(_ type: T.Type) throws -> T {
let scalar = try self.scalar()
Expand All @@ -362,33 +362,32 @@ extension _Decoder: SingleValueDecodingContainer {
}
return constructed
}



private func dereferenceAnchor<T>(_ type: T.Type) -> T? {
guard let anchor = self.node.anchor else {
return nil
}

guard let strategy = userInfo[.aliasDereferencingStrategy] as? any AliasDereferencingStrategy else {

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 371 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type
return nil
}

guard let existing = strategy[anchor] as? T else {
return nil
}

return existing
}

private func recordAnchor<T>(_ constructed: T) {
guard let anchor = self.node.anchor else {
return
}

guard let strategy = userInfo[.aliasDereferencingStrategy] as? any AliasDereferencingStrategy else {

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 14 with Xcode 15.4

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 15.0

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

cannot find type 'AliasDereferencingStrategy' in scope

Check failure on line 387 in Sources/Yams/Decoder.swift

View workflow job for this annotation

GitHub Actions / macOS 13 with Xcode 14.3

reference to member 'aliasDereferencingStrategy' cannot be resolved without a contextual type
return
}

return strategy[anchor] = constructed
}
}
Expand Down
1 change: 1 addition & 0 deletions Tests/YamsTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_library(YamsTests
AnchorCodingTests.swift
AnchorTolerancesTests.swift
ClassReferenceDecodingTests.swift
ConstructorTests.swift
EmitterTests.swift
EncoderTests.swift
Expand Down
76 changes: 37 additions & 39 deletions Tests/YamsTests/ClassReferenceDecodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ class ClassReferenceDecodingTests: XCTestCase {
- *simple
""" )

guard let decoded else { return }

XCTAssertTrue(decoded[0] === decoded[1], "Class reference not unique")
}

/// If types conform to YamlAnchorProviding and are Hashable-Equal then HashableAliasingStrategy aliases them
func testEncoderAutoAlias_Hashable_duplicateAnchor_objectCoalescing() throws {
let simpleStruct1 = SimpleWithAnchor(nested: .init(stringValue: "it's a value"), intValue: 52)
let simpleStruct2 = SimpleWithAnchor(nested: .init(stringValue: "it's a value"), intValue: 52)

let sameTypeOneAnchorPair = SimplePair(first: simpleStruct1, second: simpleStruct2)

let encodingOptions = YAMLEncoder.Options(redundancyAliasingStrategy: HashableAliasingStrategy())
Expand All @@ -57,9 +57,9 @@ class ClassReferenceDecodingTests: XCTestCase {
second: *simple
""" )

guard let decoded else { return }

XCTAssertTrue(decoded.first === decoded.first, "Class reference not unique")
}

Expand All @@ -82,9 +82,9 @@ class ClassReferenceDecodingTests: XCTestCase {
- *2
""" )

guard let decoded else { return }

XCTAssertTrue(decoded[0] === decoded[1], "Class reference not unique")
}

Expand Down Expand Up @@ -115,9 +115,9 @@ class ClassReferenceDecodingTests: XCTestCase {
intValue: *4
""" )

guard let decoded else { return }

XCTAssertTrue(decoded.first.nested === decoded.second.nested, "Class reference not unique")
}

Expand Down Expand Up @@ -150,9 +150,9 @@ class ClassReferenceDecodingTests: XCTestCase {
intValue: *5
""" )

guard let decoded else { return }

XCTAssertTrue(decoded.first.nested === decoded.second.nested, "Class reference not unique")
}

Expand Down Expand Up @@ -181,21 +181,20 @@ class ClassReferenceDecodingTests: XCTestCase {
second: *2
""" )

guard let decoded else { return }

/// It is expected and rational behavior that if an aliased value is decoded into two different types
/// that those types cannot share object identity (a memory address)
XCTAssertTrue(decoded.first !== decoded.second, "Class reference is unique")



/// It would be nice,
/// if objects contained within aliased values which are decoded different types could still identify and preserve the
/// object identity of those contained objects. (If ivars of different types could share reference to common data)
/// but is asking too much....
/// if objects contained within aliased values which are decoded different types could still identify and
/// preserve the object identity of those contained objects.
/// (If ivars of different types could share reference to common data)
/// but is asking too much....
XCTAssertFalse(decoded.first.nested === decoded.second.nested, "You fixed it!")



/// The reality of the behavior is that if you declared to decode an aliased value into two different classes,
/// you forfeit the possibility of down-graph reference sharing.
XCTAssertTrue(decoded.first.nested !== decoded.second.nested, "Class reference is unique")
Expand All @@ -213,15 +212,15 @@ class ClassReferenceDecodingTests: XCTestCase {

private class NestedStruct: Codable, Hashable {
let stringValue: String

init(stringValue: String) {
self.stringValue = stringValue
}

static func == (lhs: NestedStruct, rhs: NestedStruct) -> Bool {
lhs.stringValue == rhs.stringValue
}

func hash(into hasher: inout Hasher) {
hasher.combine(stringValue)
}
Expand All @@ -238,19 +237,19 @@ private class SimpleWithAnchor: SimpleProtocol, YamlAnchorProviding {
let nested: NestedStruct
let intValue: Int
let yamlAnchor: Anchor?

init(nested: NestedStruct, intValue: Int, yamlAnchor: Anchor? = "simple") {
self.nested = nested
self.intValue = intValue
self.yamlAnchor = yamlAnchor
}

static func == (lhs: SimpleWithAnchor, rhs: SimpleWithAnchor) -> Bool {
lhs.nested == rhs.nested &&
lhs.intValue == rhs.intValue &&
lhs.yamlAnchor == rhs.yamlAnchor
}

func hash(into hasher: inout Hasher) {
hasher.combine(nested)
hasher.combine(intValue)
Expand All @@ -261,69 +260,68 @@ private class SimpleWithAnchor: SimpleProtocol, YamlAnchorProviding {
private class SimpleWithoutAnchor: SimpleProtocol {
let nested: NestedStruct
let intValue: Int

init(nested: NestedStruct, intValue: Int) {
self.nested = nested
self.intValue = intValue
}

static func == (lhs: SimpleWithoutAnchor, rhs: SimpleWithoutAnchor) -> Bool {
lhs.nested == rhs.nested &&
lhs.intValue == rhs.intValue
}

func hash(into hasher: inout Hasher) {
hasher.combine(nested)
hasher.combine(intValue)
}
}

private class SimpleWithoutAnchor2: SimpleProtocol {

let nested: NestedStruct
let intValue: Int
// swiftlint:disable unused_declaration
let unrelatedValue: String?

init(nested: NestedStruct, intValue: Int, unrelatedValue: String? = nil) {
self.nested = nested
self.intValue = intValue
self.unrelatedValue = unrelatedValue
}


static func == (lhs: SimpleWithoutAnchor2, rhs: SimpleWithoutAnchor2) -> Bool {
lhs.nested == rhs.nested &&
lhs.intValue == rhs.intValue &&
lhs.unrelatedValue == rhs.unrelatedValue
}

func hash(into hasher: inout Hasher) {
hasher.combine(nested)
hasher.combine(intValue)
hasher.combine(unrelatedValue)
}

}

private class SimpleWithStringTypeAnchorName: SimpleProtocol {

let nested: NestedStruct
let intValue: Int
let yamlAnchor: String?

init(nested: NestedStruct, intValue: Int, yamlAnchor: String? = "StringTypeAnchor") {
self.nested = nested
self.intValue = intValue
self.yamlAnchor = yamlAnchor
}

static func == (lhs: SimpleWithStringTypeAnchorName, rhs: SimpleWithStringTypeAnchorName) -> Bool {
lhs.nested == rhs.nested &&
lhs.intValue == rhs.intValue &&
lhs.yamlAnchor == rhs.yamlAnchor
}

func hash(into hasher: inout Hasher) {
hasher.combine(nested)
hasher.combine(intValue)
Expand Down
4 changes: 2 additions & 2 deletions Tests/YamsTests/EncoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ where T: Codable, T: Equatable {
let decoded = try decoder.decode(T.self, from: producedYAML)
XCTAssertEqual(decoded, value, "\(T.self) did not round-trip to an equal value.",
file: (file), line: line)

return decoded

} catch let error as EncodingError {
Expand All @@ -473,7 +473,7 @@ where T: Codable, T: Equatable {
} catch {
XCTFail("Rout trip test of \(T.self) failed with error: \(error)", file: (file), line: line)
}

return nil
}

Expand Down

0 comments on commit 3c1cafa

Please sign in to comment.