GithubHelp home page GithubHelp logo

Comments (7)

dustdfg avatar dustdfg commented on June 27, 2024

I confirm it leads to crash on current master c64add2 with

Micro encountered an error: runtime.errorString runtime error: comparing uncomparable type action.KeySequenceEvent
runtime/alg.go:266 (0x40519a)
github.com/zyedidia/micro/v2/internal/action/bindings.go:282 (0x8ac385)
github.com/zyedidia/micro/v2/internal/action/command.go:673 (0x8b67df)
github.com/zyedidia/micro/v2/internal/action/command.go:989 (0x8b9144)
github.com/zyedidia/micro/v2/internal/action/actions.go:1545 (0x8a8092)
github.com/zyedidia/micro/v2/internal/info/infobuffer.go:152 (0x87d494)
github.com/zyedidia/micro/v2/internal/action/infopane.go:206 (0x8bd68c)
github.com/zyedidia/micro/v2/internal/action/infopane.go:54 (0x8bc656)
github.com/zyedidia/micro/v2/internal/action/infopane.go:129 (0x8bcea2)
github.com/zyedidia/micro/v2/internal/action/infopane.go:93 (0x8bcb5e)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:476 (0x8f0287)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:395 (0x8efc9e)
runtime/proc.go:250 (0x43afd2)
runtime/asm_amd64.s:1594 (0x46a9a1)

Manually setting values int the bindings.json file works

from micro.

khaytsus avatar khaytsus commented on June 27, 2024

Out of curiosity I tried to see if this was a regression and it seems like it maybe has always been this way, 2.0.7 was the first version that seemed to support this syntax and it crashes similarly.

from micro.

dustdfg avatar dustdfg commented on June 27, 2024

By adding small print in the code before error, I understood why it reports uncomparable types

screen-1710855638

screen-1710855662

function findEvent internally use two functions: findSingleEvent for single events and findEvents for frequencies. First returns one event while another returns an array of such events wrapped to an object. So you can't compare. These two types are uncomparable but findEvent just a facade that returns one of the result of those two functions.

func findEvents(k string) (b KeySequenceEvent, ok bool, err error) {
var events []Event = nil
for len(k) > 0 {
groups := r.FindStringSubmatchIndex(k)
if len(groups) > 3 {
if events == nil {
events = make([]Event, 0, 3)
}
e, ok := findSingleEvent(k[groups[2]:groups[3]])
if !ok {
return KeySequenceEvent{}, false, errors.New("Invalid event " + k[groups[2]:groups[3]])
}
events = append(events, e)
k = k[groups[3]+1:]
} else {
return KeySequenceEvent{}, false, nil
}
}
return KeySequenceEvent{events}, true, nil
}

func findSingleEvent(k string) (b Event, ok bool) {

But I am curios why does type system doesn't report it as a problem? I findEvent returns Event as like findSingleEvent but findEvents returns KeySequenceEvent how it can fit there?

func findEvent(k string) (Event, error) {
var event Event
event, ok, err := findEvents(k)
if err != nil {
return nil, err
}
if !ok {
event, ok = findSingleEvent(k)
if !ok {
return nil, errors.New(k + " is not a bindable event")
}
}
return event, nil
}

from micro.

JoeKar avatar JoeKar commented on June 27, 2024

Interesting, before the comparison they should...at least from my understanding...type checked and in case of KeySequenceEvent iterated once again and within that iteration compared against the entry, which is a KeyEvent.

from micro.

dustdfg avatar dustdfg commented on June 27, 2024

You iterate through all the bindings in the bindings.json And then compare them with event passed to TryBindKey. If we will represent it like array of events in the bindings.json we will get something like [Event,Event,KeySequenceEvent,Event,...]. When you call the TryBindKey you iterate trough this array and will check all the elemnts one by one if it is equal to the event you passed to TryBindKey so it leads to bug

from micro.

dustdfg avatar dustdfg commented on June 27, 2024

Or maybe I am wrong. I am almost always wrong ¯\_(ツ)_/¯. I've just deleted from my bindings all the events in order to prevent check between Event and KeySequenceEvent and the problem still persist 😅

from micro.

dmaluka avatar dmaluka commented on June 27, 2024

https://go.dev/ref/spec#Comparison_operators

Interface types that are not type parameters are comparable. Two interface values are equal if they have identical dynamic types and equal dynamic values or if both have value nil.

Struct types are comparable if all their field types are comparable.

A comparison of two interface values with identical dynamic types causes a run-time panic if that type is not comparable.

KeyEvent is a comparable type, KeySequenceEvent is not.

So comparing KeyEvent with KeyEvent is legal, comparing KeyEvent with KeySequenceEvent is also legal (and always returns false), but comparing KeySequenceEvent with KeySequenceEvent triggers a panic.

from micro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.