Skip to content

Crash when trying to use type.name[0]  #12804

@alehander92

Description

@alehander92

I tried to use [0] for a type name and it leads to crash

Example

import typetraits, strutils

type
  AbComponent* = object

template local*(expression: untyped): untyped {.dirty.} =
  # this fails
  # $(expression.type.name[0]) 
  expression.type.name[0 .. 0]
  

var self = AbComponent()
echo local(2)

Current Output

If you comment out, it crashes with

fatal.nim(39) sysFatal
Error: unhandled exception: index out of bounds, the container is empty [IndexError] 

Expected Output

Running correctly and returning the first char

Possible Solution

  • Don't know yet

Additional Information

  • It works if i use [0 .. 0] so this is a workaround
$ nim -v
Nim Compiler Version 1.1.1 [Linux: amd64]
Compiled at 2019-12-02
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 2acf74d458accf65d969199a389c8dbc2eedab55
active boot switches: -d:release

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions