edubart / nelua-lang

Minimal, efficient, statically-typed and meta-programmable systems programming language heavily inspired by Lua, which compiles to C and native code.
https://nelua.io
MIT License
1.99k stars 64 forks source link

`<deprecated>` is silenced by type inference #232

Closed jrfondren closed 10 months ago

jrfondren commented 10 months ago

Bug description

local x: integer <deprecated> = 1  // generates the warning when used
local x: <deprecated> = 1  // does not do this

I realize this is a very minor bug in an undocumented feature. I'm not trying for a high score of bug reports, I'm just leaning towards making issues while exploring the language. In this case, exploring the annotations in typedefs.lua. If you don't want bug reports like this, let me know and I'll hold onto them.

Code example

## if pragmas.bug then
  local x <deprecated> = 1
  ## print(x.type)
  ## print(require'inspect'(x.possibletypes, {depth=2}))
## else
  local x: integer <deprecated> = 1
  ## print(x.type)
## end
print(x)

Expected behavior

With and without -P bug, this should emit warning: use of deprecated symbol 'x'

Workaround

Provide a type. Or check in after_analyze:

##[[
function deprecate(sym)
  local console = require 'nelua.utils.console'
  after_analyze(hygienize(function()
    if symbols[sym.name]:is_used() then
      console.warn('use of deprecated symbol ' .. sym.name)
    end
  end))
end
]]

local x = 1           ## deprecate(x)
local y: integer = 2  ## deprecate(y)
local z: number = 3   ## deprecate(z)
print(x)
print(y)

Environment

x86_64 linux Nelua 0.2.0-dev Build number: 1588 Git date: 2023-09-16 16:20:44 -0300 Git hash: 596fcca5c77932da8a07c249de59a9dff3099495 Semantic version: 0.2.0-dev.1588+596fcca5 Copyright (C) 2019-2022 Eduardo Bart (https://nelua.io/)

edubart commented 10 months ago

No problem making these bug reports, this helps the project, I will probably take a look and fix some of them in a batch later. Most of issues you found so far are not critical, but not ideal to leave them there.