Skip to content

confusion between functions, identifiers, and names #24

@julochrobak

Description

@julochrobak

I looked at the possibility to support some basic namespaces for built-in functions, for example math for mathematical functions (math.Round, math.Trunc, math.Abs), or str for string operations (str.Title, str.ToLower), and so on... However, I realized there is a bug with the current implementation which is somehow related to what looked at, i.e. IDENT '.' IDENT ( … ) or postfix_expression '.' postfix_expression (…).

The issue is that every function name is registered in the "names" map of the declarations, and the Decls.UseIdent function registers it as an identifier as well, always with a nil value because no value is ever assigned to this identifier, which is in fact just a function name…

This confusion between names, identifiers, and functions also leads to variety of strange situations:

$ bin/comp '{trunc}'
{ "trunc": panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x48 pc=0x15d77]

goroutine 1 [running]:
main.Object.Quote(0xc2000bf750, 0x1, 0x1, 0xc2000c0420, 0xc200000008, ...)
/Users/julo/comp/src/comp/value.go:252 +0x417
main.(*Object).Quote(0xc200090680, 0xc2000c0420, 0xc200000008,     0xc2000c0c90, 0xc200090620, ...)
/Users/julo/comp/src/comp/decls.go:0 +0xb3
main.Command(0x7fff5fbffae1, 0x7, 0x2b40a0, 0x0, 0x24, ...)
/Users/julo/comp/src/comp/main.go:32 +0x1cd
main.main()
/Users/julo/comp/src/comp/main.go:90 +0x1a0

goroutine 2 [syscall]:

goroutine 3 [runnable]:

$ bin/comp 'trunc'
$

$ bin/comp '[ 0 | trunc <- [0,1], trunc(trunc) ]'
[ 0 ]

$ bin/comp '[ trunc | trunc <- [0,1], trunc(trunc) ]'
'trunc' is already declared

$ bin/comp '[ trunc | t <- [0,1], trunc(t) ]'
[ panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x48 pc=0x15709]
…

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions