Skip to content
New issue

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

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

Already on GitHub? # to your account

Compilation panics when names of a custom action's array parameter and another variable are the same #67

Closed
NoelTautges opened this issue Jun 20, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@NoelTautges
Copy link
Contributor

NoelTautges commented Jun 20, 2024

Describe the bug

When compiling a Cherri file where names of a custom action's array parameter and an unrelated variable/constant are the same, the compiler panics.

To Reproduce

action customAction(array overlappingName) {
}

const overlappingName = 0
customAction(overlappingName)

Debug output

Parsing overlapping_names.cherri...
Parsing includes...
### INCLUDES ###

## INCLUDED ##
[]

## INCLUDES MAP ##
[]

Done.

### CUSTOM ACTIONS ###

identifier: customAction()
used: true
parameters:
[{overlappingName array  <nil> [] false false}]
body:

(end)

if ShortcutInput {
    const _cherri_inputType = typeOf(ShortcutInput)
    if _cherri_inputType == "Dictionary" {
        const _cherri_input = getDictionary(ShortcutInput)
        const _cherri_identifier = getValue(_cherri_input, "cherri_functions")
        const _cherri_valid = number(_cherri_identifier)
        if _cherri_valid == true {
            const _cherri_function = getValue(_cherri_input, "function")
            const _cherri_function_name = "{_cherri_function}"
            const _cherri_function_args = getValue(_cherri_input, "arguments")
            if _cherri_function_name == "customAction" {
                const _cherri_customAction_arg_1_overlappingName = getListItem(_cherri_function_args, 1)
                @overlappingName: array
                const _cherri_customAction_arg_1_overlappingName_array_dictionary = getDictionary(_cherri_customAction_arg_1_overlappingName)
                const _cherri_customAction_arg_1_overlappingName_array = getValue(_cherri_customAction_arg_1_overlappingName,"array")
                for _cherri_customAction_arg_1_overlappingName_array_item in _cherri_customAction_arg_1_overlappingName_array {
                    @overlappingName += _cherri_customAction_arg_1_overlappingName_array_item
                }

output(nil)
            }
            output(nil)
        }
    }
}



const overlappingName = 0
customAction(overlappingName)
 
Writing processed version to chicky_tests/nil_pointer/overlapping_name_processed.cherri...Done.
### PARSING ###

Previous Character:
SPACE 31:1

Current Character:
EMPTY 31:1

Current Line:
 
## TOKENS ##
 1 | {conditional 773ebbc9-b35f-44a4-b834-cb751f7a15dc if {variable ShortcutInput 100  <nil>  <nil>}}
 2 | {variable _cherri_inputType action {typeOf [{variable ShortcutInput}]}}
 3 | {conditional 75da7d73-4d20-45fc-b2d6-db05a79fa308 if {variable _cherri_inputType 4 text Dictionary  <nil>}}
 4 | {variable _cherri_input action {getDictionary [{variable ShortcutInput}]}}
 5 | {variable _cherri_identifier action {getValue [{variable _cherri_input} {text cherri_functions}]}}
 6 | {variable _cherri_valid action {number [{variable _cherri_identifier}]}}
 7 | {conditional 1758c609-e2a9-4eb9-a40a-37bb2345a4e1 if {variable _cherri_valid 4 bool %!s(bool=true)  <nil>}}
 8 | {variable _cherri_function action {getValue [{variable _cherri_input} {text function}]}}
 9 | {variable _cherri_function_name text {_cherri_function}}
10 | {variable _cherri_function_args action {getValue [{variable _cherri_input} {text arguments}]}}
11 | {conditional 8ba36385-dff3-4039-9136-4a340e94e696 if {variable _cherri_function_name 4 text customAction  <nil>}}
12 | {variable _cherri_customAction_arg_1_overlappingName action {getListItem [{variable _cherri_function_args} {number 1}]}}
13 | {variable overlappingName array <nil>}
14 | {variable _cherri_customAction_arg_1_overlappingName_array_dictionary action {getDictionary [{variable _cherri_customAction_arg_1_overlappingName}]}}
15 | {variable _cherri_customAction_arg_1_overlappingName_array action {getValue [{variable _cherri_customAction_arg_1_overlappingName} {text array}]}}
16 | {for  cf73786a-3878-4022-be41-4be1cad11d58 variable _cherri_customAction_arg_1_overlappingName_array}
17 | {variable _cherri_customAction_arg_1_overlappingName_array_item variable Repeat Item}
18 | {+= overlappingName variable _cherri_customAction_arg_1_overlappingName_array_item}
19 | {action nothing action {nothing []}}
20 | {for  cf73786a-3878-4022-be41-4be1cad11d58 endif <nil>}
21 | {action output action {output [{nil <nil>}]}}
22 | {action nothing action {nothing []}}
23 | {conditional 8ba36385-dff3-4039-9136-4a340e94e696 endif <nil>}
24 | {action output action {output [{nil <nil>}]}}
25 | {action nothing action {nothing []}}
26 | {conditional 1758c609-e2a9-4eb9-a40a-37bb2345a4e1 endif <nil>}
27 | {action nothing action {nothing []}}
28 | {conditional 75da7d73-4d20-45fc-b2d6-db05a79fa308 endif <nil>}
29 | {action nothing action {nothing []}}
30 | {conditional 773ebbc9-b35f-44a4-b834-cb751f7a15dc endif <nil>}
31 | {variable overlappingName number 0}
32 | {variable _customAction_cherri_call dictionary map[arguments:[map[array:<nil>]] cherri_functions:%!s(float64=1) function:customAction]}
33 | {action runSelf action {runSelf [{variable _customAction_cherri_call}]}}

## DEFINITIONS ##
Name: overlapping_name
Color: -1263359489
Glyph: 61440
Inputs: []
Outputs: []
Workflows: []
No Input: { []}
macOS Only: false
Mininum Version: 2106.0.3
iOS Version: 17.0

## VARIABLES ##
const _cherri_function_name = {_cherri_function} (text)
const _cherri_function_args = {getValue [{variable _cherri_input} {text arguments}]} (action)
const _cherri_customAction_arg_1_overlappingName = {getListItem [{variable _cherri_function_args} {number 1}]} (action)
const _cherri_inputType = {typeOf [{variable ShortcutInput}]} (action)
const _cherri_input = {getDictionary [{variable ShortcutInput}]} (action)
const _cherri_identifier = {getValue [{variable _cherri_input} {text cherri_functions}]} (action)
const _cherri_valid = {number [{variable _cherri_identifier}]} (action)
const _cherri_function = {getValue [{variable _cherri_input} {text function}]} (action)
@overlappingName (array)
@_cherri_customAction_arg_1_overlappingName_array_item = _cherri_customAction_arg_1_overlappingName_array_item (text) (repeat item var)
const _cherri_customAction_arg_1_overlappingName_array_dictionary = {getDictionary [{variable _cherri_customAction_arg_1_overlappingName}]} (action)
const _cherri_customAction_arg_1_overlappingName_array = {getValue [{variable _cherri_customAction_arg_1_overlappingName} {text array}]} (action)
const customAction = map[arguments:[map[array:<nil>]] cherri_functions:%!s(float64=1) function:customAction] (dictionary)

## MENUS ##
map[]

## IMPORT QUESTIONS ##
map[]

Done.

Generating plist...panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xf8 pc=0x6c3627]

goroutine 1 [running]:
main.dictionaryValue({0xc0000b9189, 0x5}, {0x0, 0x0})
        [snip]/cherri/plist.go:946 +0x167
main.makeDictionary(...)
        [snip]/cherri/plist.go:926
main.dictionaryValue({0x0, 0x0}, {0x6fe7e0, 0xc0000ad380})
        [snip]/cherri/plist.go:991 +0x765
main.dictionaryValue({0xc0000b9180, 0x9}, {0x6eb3a0, 0xc0000b40c0})
        [snip]/cherri/plist.go:970 +0xaed
main.makeDictionary(...)
        [snip]/cherri/plist.go:926
main.makeDictionaryValue(0x7fcdce6f2448?)
        [snip]/cherri/plist.go:311 +0xe9
main.makeVariableValue(0xc0000330e0, 0xc000033110, {0x74e710?, 0x7fce169c05b8?}, 0x10?)
        [snip]/cherri/plist.go:200 +0x29d
main.makeVariableAction(0xc0000335a0, 0xc00003320c?)
        [snip]/cherri/plist.go:173 +0x3da
main.plistVariable(0xc0000335a0)
        [snip]/cherri/plistgen.go:219 +0x14b
main.plistActions()
        [snip]/cherri/plistgen.go:175 +0x60b
main.makePlist()
        [snip]/cherri/plistgen.go:37 +0x273
main.main()
        [snip]/cherri/main.go:78 +0x3e5

Expected behavior

I expected compilation to either succeed or fail with an error message. Instead, the compiler panics.

Version Information:

  • Linux version: Linux 4.4.0-22621-Microsoft #3672-Microsoft Fri Jan 01 08:00:00 PST 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Golang version: go version go1.22.3 linux/amd64

Additional context

It only panics if the parameter is an array. I wonder if it's a broader case of overlapping names, made worse because array parameters are processed specially. I'll try to look into this tomorrow.

@NoelTautges NoelTautges added the bug Something isn't working label Jun 20, 2024
@electrikmilk electrikmilk self-assigned this Jul 31, 2024
electrikmilk added a commit that referenced this issue Aug 5, 2024
This fix comes with the caveat of, if a value is empty, we won't create
a value of that type because we have no way of knowing it if you didn't
provide a value since valid JSON defines the dictionary and array types.
@electrikmilk
Copy link
Owner

This has been fixed with f7b6a25.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants