Skip to content

Fix @Entity decoding of String identifiers - #40

Open
colemancda wants to merge 1 commit into
masterfrom
fix/string-entity-id
Open

colemancda wants to merge 1 commit into
masterfrom
fix/string-entity-id

Conversation

@colemancda

Copy link
Copy Markdown
Member

The init(from:) generated by @Entity used guard let id = Self.ID(objectID: container.id), which fails to compile when ID is String ("initializer for conditional binding must have Optional type"), because String.init(objectID:) is not failable.

  • Adds ObjectID.convert(to:), which returns an optional for any ObjectIDConvertible type.
  • The macro now generates guard let id = container.id.convert(to: Self.ID.self).

Tests:

  • Macro assertions: new stringIdentifier() test, and structExpansion() checks the ID line.
  • New StringIdentifierTests with a String-ID entity: encoding, decoding, wrong entity name, insert and fetch.
  • convert(to:) expectations added to objectID().

The generated init(from:) bound Self.ID(objectID:) with guard let, which does
not compile for String, whose init(objectID:) is not failable. Convert through
ObjectID.convert(to:), which always calls the failable protocol requirement.
@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: Swift

Swift / code-coverage/llvm-cov

master 456c3e1 fix/string-entity-id e921c3d +/-
96% 96% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant