Skip to content

Dot operators with type mismatch, shows assertion instead of compiler error #17779

@jtiai

Description

@jtiai

The following code doesn't compile and causes unhandled exception:

Example

{.experimental: "dotOperators".}

type
    Flag = enum
        A

    Flags = set[Flag]

template `.=`*(flags: Flags, key: Flag, val: bool) =
    if val: flags.incl key else: flags.excl key

var flags: Flags

flags.A = 123

Current Output

....fatal.nim(53)            sysFatal
Error: unhandled exception: semcall.nim(233, 18) `nArg != nil`  [AssertionDefect]

Expected Output

Compiler provides meanful error message or compiles.

Possible Solution

If flags.A = 123 is written as flags.A = bool(123) code compiles as expected.

$ nim -v
Nim Compiler Version 1.4.6 [Linux: amd64]
# make sure to include the git hash if not using a tagged release

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions