Skip to content

variant with @tag, inline record payload, and duplicate custom tag compiles / produces unsafe code #7438

Closed
@illusionalsagacity

Description

@illusionalsagacity

Thank you for filing! Check list:

  • Is it a bug? Usage questions should often be asked in the forum instead.
  • Concise, focused, friendly issue title & description.
  • A minimal, reproducible example.
  • OS and browser versions, if relevant.
  • Is it already fixed in master? Instructions

When using a @tag variant type with an inline record definition, we lose the error calling out a duplicate tag: "This untagged variant definition is invalid: Duplicate literal foo."

Here's an example with a boolean tag but this also does not produce the compiler error for ints / strings in the playground link

@tag("type")
type ex =
  | @as(true) True({data: string})
  | @as(false) False({data: unit})
  | @as(false) Third({data: unit, foo: string})


let parse = value => switch value {
  | True({data}) => Console.log(data)
  | False(_) => Console.log("false")
  | Third({foo}) => Console.log2("foo: ", foo)
}

https://rescript-lang.org/try?version=v12.0.0-alpha.10&module=esmodule&code=AIFwhg5gFARCCeAHApjAlAKASgBAZxACcBLAOwgFEAPHAXgxxwB8dgw9YAzAe2-RwAqhAK7IoAbwAmYcAC58RMhAC+mRizYcYAIzCF+AMTAAbPGKkyw84aWIhVDZq3Zde-AQAtihSROlycGzsAGhwebnkCEnIHDAxQSFhsVExknG1eY2o6Rw0XIlE0QRFzfysFaJU1J00oThMzIqNTUstrW3tqvI56lqLPb18LAKCQUPDIxRjMePBoOCQUrEWcMhBs+nVnDgBGfpK-NoqlBy3agCYmhtaRjtOalz3BLx9D25Cw3knK2ONkEBwiD0ZjoOCgADcTKJvkpqEVaAA+fAAdzsAGMPDhIcZRDhxLliqI3mBVHQkQBhbikPDcP4AOmM3GgZS6OGaZigAH14RSqTT6Yz5r0zOgCQNXuJwqTEThKdTacgGUzzq4IjgYONeJhlHE-gCgYQzOdQRCoch5BlaXCySj0Zjsbj8VshEThiSebK+QqlczLKz2WJuTa5fzFYKuNdRc6XkMpR6Q97BSqYBN1ZruNrdf9AcDkABmE0O82rUjrKgevCokAYrFmvFig5u6W8+UCplQFkEgNc+NettCyOs8Wx3jNz2tsPK1XyDWfDMYZRAA

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions