Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No line number in error if a hashmap index has a type error #241

Open
jrfondren opened this issue Nov 14, 2023 · 0 comments
Open

No line number in error if a hashmap index has a type error #241

jrfondren opened this issue Nov 14, 2023 · 0 comments
Labels

Comments

@jrfondren
Copy link

Code example

require 'hashmap'
require 'string'

local map: hashmap(integer, record{word: string, reading: string})
local row: record{id: string, word: string, reading: string}

local id = tonumber(row.id)
map[row] = { -- oops! should be: map[id]
  word    = row.word,
  reading = row.reading,
}

With output:

hasherrormsg.nelua:1:1: from: AST node Block
require 'hashmap'
^~~~~~~~~~~~~~~~~
error: in call of function 'hashmap(int64, V).__atindex' at argument 1: no viable type conversion from 'record{id: string, word: string, reading: string}' to 'int64'

Expected behavior

An error message pointing to the map[row], similar to

require 'hashmap'
require 'string'

local map: hashmap(integer, record{word: string, reading: string})
local row: record{id: string, word: string, reading: string}
local function set(k: #[map.type.K]#, v: #[map.type.V]#) map[k] = v end

local id = tonumber(row.id)
set(row, { -- oops! should be: map[id]
  word    = row.word,
  reading = row.reading,
})

Which has this output:

hasherrormsg2.nelua:1:1: from: AST node Block
require 'hashmap'
^~~~~~~~~~~~~~~~~
hasherrormsg2.nelua:9:4: error: in call of function 'set' at argument 1: no viable type conversion from 'record{id: string, word: string, reading: string}' to 'int64'
set(row, { -- oops! should be: map[id]
   ^~~~~~~

Environment

Linux x86_64
Nelua 0.2.0-dev
Build number: 1605
Git date: 2023-11-05 16:12:59 -0300
Git hash: decf713
Semantic version: 0.2.0-dev.1605+decf713c
Copyright (C) 2019-2023 Eduardo Bart (https://nelua.io/)

@jrfondren jrfondren added the bug label Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant