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

Vim9: Internal error with this queried in variable initialisers #14411

Open
zzzyxwvut opened this issue Apr 4, 2024 · 0 comments
Open

Vim9: Internal error with this queried in variable initialisers #14411

zzzyxwvut opened this issue Apr 4, 2024 · 0 comments
Labels
bug vim9class Vim 9 Class Functionality

Comments

@zzzyxwvut
Copy link
Contributor

Steps to reproduce

(Before the failing class examples, I have included a couple
of working class examples named TestPassing*.)

Example 1:

vim9script

class TestPassing1
    const one: number = TestPassing1.One(this)

    static def One(that: TestPassing1): number
	return 1
    enddef
endclass

echo TestPassing1.One(TestPassing1.new())

class TestPassing2
    const one: number = 1
    const two: number = TestPassing2.Two(this)

    static def Two(that: TestPassing2): number
	return that.one + 1
    enddef
endclass

echo TestPassing2.Two(TestPassing2.new())


class Test2
    const two: number = Test2.Two(this)
    const one: number = 1

    static def Two(that: Test2): number
	return that.one + 2
    enddef
endclass

# E340
echo Test2.Two(Test2.new())

Example 2:

vim9script

class TestPassing1
    const Id: func(any): any = ((_) => (v) => v)(this)

    static def Id(that: TestPassing1): func(any): any
	return that.Id
    enddef
endclass

echo TestPassing1.Id(TestPassing1.new())(1)
echo TestPassing1.new().Id(1)

class Test1
    const Id: func(any): any = ((that) => (_) => that)(this)

    static def Id(that: Test1): func(any): any
	return that.Id
    enddef
endclass

# E340
const Id0: func(any): any = Test1.Id(Test1.new())
# E340
const Id1: func(any): any = Test1.new().Id

class Test2
    const Id: any = Test2.Id(this)

    static def Id(that: Test2): any
	return that.Id
    enddef
endclass

# E340
const Id2: any = Test2.Id(Test2.new())
# E340
const Id3: any = Test2.new().Id

Expected behaviour

Each failure can probably be justified on the grounds of
interfering with step 2.

The sequence of constructing a new object is:
1. Memory is allocated and cleared. All values are zero/false/empty.
2. For each declared object variable that has an initializer, the expression
is evaluated and assigned to the variable. This happens in the sequence
the variables are declared in the class.

Do we need a dedicated EXXX for an inappropriate state?

Version of Vim

v9.1.0263

Environment

GNU/Linux Debian (testing/trixie)

Logs and stack traces

No response

@zzzyxwvut zzzyxwvut added the bug label Apr 4, 2024
@yegappan yegappan added the vim9class Vim 9 Class Functionality label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug vim9class Vim 9 Class Functionality
Projects
None yet
Development

No branches or pull requests

2 participants