nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.55k stars 1.47k forks source link

Internal error: '=destroy' operator not found for type #21601

Open al6x opened 1 year ago

al6x commented 1 year ago

Description

This code would crash compiler

type Person = object

type Builder* = ref object of RootObj
  class*: typedesc

echo Builder(class: Person).repr

Nim Version

Nim Compiler Version 1.6.12 [MacOSX: amd64] Compiled at 2023-03-10 Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release -d:nimUseLinenoise

Current Output

It produces different errors, on my machine it's 

Hint: used config file '/usr/local/Cellar/nim/1.6.12/nim/config/nim.cfg' [Conf]
Hint: used config file '/usr/local/Cellar/nim/1.6.12/nim/config/config.nims' [Conf]
.........................................................
/alex/projects/nim/play.nim(10, 13) Error: internal error: '=destroy' operator not found for type Builder

in playground its

Error: internal error: getTypeDescAux(tyNone)
No stack traceback available
To create a stacktrace, rerun compilation with './koch temp c <file>', see https://nim-lang.github.io/Nim/intern.html#debugging-the-compiler for details


### Expected Output

_No response_

### Possible Solution

_No response_

### Additional Information

_No response_
beef331 commented 1 year ago

typedesc is not a runtime value should error inside typedefinition.

al6x commented 1 year ago

Also, the compilation error message for this code should be improved, currently it prints cryptic error and it's hard to understand what's wrong (the problem is typedesc field in Element):

import std/tables

type Element* = ref object of RootObj
  tag*:               typedesc

type App* = ref object of RootObj
  children*:         seq[Element]

type Apps* = ref Table[string, App]

proc build*(apps: Apps): App =
  discard

prints

play.nim(13, 12) Error: invalid type: 'Table[system.string, play.App]' in this context: 'proc (apps: Apps): App' for proc