forked from aniani/vim
patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Problem: Vim9: not recognizing qualified class vars for infix ops Solution: Drop the class type from the stack before generating the CLASSMEMBER instruction closes: #13378 closes: #13379 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
committed by
Christian Brabandt
parent
982ef16059
commit
d7b616d0ad
@@ -8337,4 +8337,76 @@ def Test_classmethod_timer_callback()
|
|||||||
v9.CheckSourceSuccess(lines)
|
v9.CheckSourceSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
" Test for using a class variable as the first and/or second operand of a binary
|
||||||
|
" operator.
|
||||||
|
def Test_class_variable_as_operands()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
class Tests
|
||||||
|
static truthy: bool = true
|
||||||
|
static list: list<any> = []
|
||||||
|
static four: number = 4
|
||||||
|
static hello: string = 'hello'
|
||||||
|
|
||||||
|
static def Hello(): string
|
||||||
|
return hello
|
||||||
|
enddef
|
||||||
|
|
||||||
|
static def Four(): number
|
||||||
|
return four
|
||||||
|
enddef
|
||||||
|
|
||||||
|
static def List(): list<any>
|
||||||
|
return list
|
||||||
|
enddef
|
||||||
|
|
||||||
|
static def Truthy(): bool
|
||||||
|
return truthy
|
||||||
|
enddef
|
||||||
|
|
||||||
|
def TestOps()
|
||||||
|
assert_true(Tests.truthy == truthy)
|
||||||
|
assert_true(truthy == Tests.truthy)
|
||||||
|
assert_true(Tests.list isnot [])
|
||||||
|
assert_true([] isnot Tests.list)
|
||||||
|
assert_equal(2, Tests.four >> 1)
|
||||||
|
assert_equal(16, 1 << Tests.four)
|
||||||
|
assert_equal(8, Tests.four + four)
|
||||||
|
assert_equal(8, four + Tests.four)
|
||||||
|
assert_equal('hellohello', Tests.hello .. hello)
|
||||||
|
assert_equal('hellohello', hello .. Tests.hello)
|
||||||
|
enddef
|
||||||
|
endclass
|
||||||
|
|
||||||
|
def TestOps2()
|
||||||
|
assert_true(Tests.truthy == Tests.Truthy())
|
||||||
|
assert_true(Tests.Truthy() == Tests.truthy)
|
||||||
|
assert_true(Tests.list is Tests.List())
|
||||||
|
assert_true(Tests.List() is Tests.list)
|
||||||
|
assert_equal(2, Tests.four >> 1)
|
||||||
|
assert_equal(16, 1 << Tests.four)
|
||||||
|
assert_equal(8, Tests.four + Tests.Four())
|
||||||
|
assert_equal(8, Tests.Four() + Tests.four)
|
||||||
|
assert_equal('hellohello', Tests.hello .. Tests.Hello())
|
||||||
|
assert_equal('hellohello', Tests.Hello() .. Tests.hello)
|
||||||
|
enddef
|
||||||
|
|
||||||
|
var t = Tests.new()
|
||||||
|
t.TestOps()
|
||||||
|
TestOps2()
|
||||||
|
|
||||||
|
assert_true(Tests.truthy == Tests.Truthy())
|
||||||
|
assert_true(Tests.Truthy() == Tests.truthy)
|
||||||
|
assert_true(Tests.list is Tests.List())
|
||||||
|
assert_true(Tests.List() is Tests.list)
|
||||||
|
assert_equal(2, Tests.four >> 1)
|
||||||
|
assert_equal(16, 1 << Tests.four)
|
||||||
|
assert_equal(8, Tests.four + Tests.Four())
|
||||||
|
assert_equal(8, Tests.Four() + Tests.four)
|
||||||
|
assert_equal('hellohello', Tests.hello .. Tests.Hello())
|
||||||
|
assert_equal('hellohello', Tests.Hello() .. Tests.hello)
|
||||||
|
END
|
||||||
|
v9.CheckSourceSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
||||||
|
@@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2049,
|
||||||
/**/
|
/**/
|
||||||
2048,
|
2048,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -379,6 +379,8 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
|
|||||||
}
|
}
|
||||||
if (type->tt_type == VAR_CLASS)
|
if (type->tt_type == VAR_CLASS)
|
||||||
{
|
{
|
||||||
|
// Remove the class type from the stack
|
||||||
|
--cctx->ctx_type_stack.ga_len;
|
||||||
if (generate_CLASSMEMBER(cctx, TRUE, cl, m_idx) == FAIL)
|
if (generate_CLASSMEMBER(cctx, TRUE, cl, m_idx) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@@ -475,6 +477,8 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*arg = name_end;
|
*arg = name_end;
|
||||||
|
// Remove the class type from the stack
|
||||||
|
--cctx->ctx_type_stack.ga_len;
|
||||||
return generate_CLASSMEMBER(cctx, TRUE, cl, idx);
|
return generate_CLASSMEMBER(cctx, TRUE, cl, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user