Skip to content

Add rich diagnostic; Restrict Codable & AllOfCodable to struct uses; Handle labels in enums#3

Merged
mikhailmaslo merged 12 commits intomainfrom
feature/friendly-messages
Oct 8, 2023
Merged

Add rich diagnostic; Restrict Codable & AllOfCodable to struct uses; Handle labels in enums#3
mikhailmaslo merged 12 commits intomainfrom
feature/friendly-messages

Conversation

@mikhailmaslo
Copy link
Copy Markdown
Owner

Bug fixes

  • Support of enum cases with labels
@OneOfCodable
enum Example {
  case withLabel(label: Int)
  case withUnderscoredLabel(_ label: Int)
}
  • Support optionals in enum
@OneOfCodable
enum Example {
  case optionalOneOf(Int?)
}

Diagnostic

@codable, @AllOfCodable

can be only applied to a struct
@Codable
╰─ 🛑 '@Codable' macro can only be applied to a struct
enum NoApplicable {}

@Codable
╰─ 🛑 '@Codable' macro can only be applied to a struct
class NoApplicable {}

@OneOf

Require only one associated value
@OneOfCodable
enum Example {
    case a
         
         ╰─ 🛑 '@OneOfCodable' macro requires each case to have one associated value
}

@OneOfCodable
enum InvalidEnum2 {
    case a(Int, Int)
         ┬──────────
         ╰─ 🛑 '@OneOfCodable' macro requires each case to have one associated value
}

Annotations

Duplicated declaration
@Codable
struct Example {
    @OmitCoding
    ╰─ 🛑 '@Omitcoding' attribute has been applied more than once. Redundant attribute applications have no effect on the generated code and may cause confusion.
    @OmitCoding
    let a: Int
}
Unsupported declarations
@Codable
struct Example {
    let a, b: Int
    ┬────────────
    ╰─ 🛑 '@Codable' macro is only applicable to declarations with an identifier followed by a type
}

@Codable
struct Example {
    let a: Int, b: Int
    ┬─────────────────
    ╰─ 🛑 '@Codable' macro is not applicable to compound declarations, declare each variable on a new line
}

@Codable
struct Example {
    @DefaultValue(IntZero)
    ╰─ 🛑 '@Codable' macro is only applicable to stored properties declared with an identifier followed by a type, example: `let variable: Int`
    var a: Int { 0 }
}

@mikhailmaslo mikhailmaslo merged commit c2e203f into main Oct 8, 2023
@mikhailmaslo mikhailmaslo deleted the feature/friendly-messages branch October 8, 2023 10:33
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