Skip to content

Go panic generated  #1287

Closed
Closed

Description

@pdietl

I wrote this script:

#!/usr/bin/env elvish

use path

if (not-eq (count $args) 1) {
    echo "Usage: "(path:base (src)[name])" <input file>" >&2
    exit 1
}

var numbers = [(from-lines < $args[0])]

var TARGET = 2020

# Look for pairs of numbers that add to TARGET.
# Then, print the product of those two numbers.

for i [(range (count $numbers))] {
    var a = $numbers[$i]
    for b $numbers[(+ 1 $i)..] {
        if (== (+ $a $b) $TARGET) {
            echo (* $a $b)
        }
    }
}

And ran it with the following input:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

I get the following errors:

panic: interface conversion: interface {} is nil, not vector.node

goroutine 14909 [running]:
github.com/xiaq/persistent/vector.newIteratorWithRange(0xc0000a4c60, 0x40, 0x41, 0x7e6320)
	github.com/xiaq/persistent@v0.0.0-20200820214153-3175cfb92e14/vector/vector.go:357 +0x2f4
github.com/xiaq/persistent/vector.(*subVector).Iterator(0xc000452560, 0x759740, 0xc000452560)
	github.com/xiaq/persistent@v0.0.0-20200820214153-3175cfb92e14/vector/vector.go:322 +0x45
src.elv.sh/pkg/eval/vals.Iterate(0x759740, 0xc000452560, 0xc00041a5c0, 0x0, 0x0)
	src.elv.sh/pkg/eval/vals/iterate.go:39 +0x164
src.elv.sh/pkg/eval.(*forOp).exec(0xc0001d2000, 0xc000421b90, 0xc00019b530, 0x77f749)
	src.elv.sh/pkg/eval/builtin_special.go:595 +0x2fe
src.elv.sh/pkg/eval.(*formOp).exec(0xc0001b7ce0, 0xc000421b90, 0x0, 0x0)
	src.elv.sh/pkg/eval/compile_effect.go:332 +0xf15
src.elv.sh/pkg/eval.(*pipelineOp).exec.func1(0x7dcc00, 0xc0001b7ce0, 0xc000421b90, 0xc000208300, 0xc0003706f0, 0x0)
	src.elv.sh/pkg/eval/compile_effect.go:117 +0x3f
created by src.elv.sh/pkg/eval.(*pipelineOp).exec
	src.elv.sh/pkg/eval/compile_effect.go:116 +0x228
Exception: ./01.elv exited with 2
[tty 125], line 1: ./01.elv input.tt

If you remove one line from that input file, then no exception is generated.

Activity

  1. krader1961 commented on Apr 11, 2021

    @krader1961
    Contributor

    I can reproduce with elvish built from master branch (commit 9b276a3). Note that while removing one or more lines eliminates the panic adding lines does not.

    @pdietl: It's always important to include information about the relevant software versions when reporting a problem. It's especially important since Elvish is rapidly evolving; see https://elv.sh/blog/ and https://github.com/elves/elvish/graphs/commit-activity.

    @xiaq: One thing I noticed is that with the introduction of the new number types the not-eq (count $args) 1 expression in the reproduction script now evaluates to true when the count is, in fact, one. I'll open an issue for that.

  2. pdietl commented on Apr 11, 2021

    @pdietl
    Author

    @krader1961 Yes will do in the future. I am using v0.16.0-dev.2a1eda6bb008a5852b1a3fcb99aac92dd9a7f39d

  3. added this to the 0.16.0 milestone on May 3, 2021
  4. xiaq commented on May 3, 2021

    @xiaq
    Member

    Minimum repro:

    all [(range 65)][64..]
    
  5. added a commit that references this issue on May 3, 2021
  6. added a commit that references this issue on Mar 3, 2024
    7fa2fc7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions