Patch 7.4.1546
Problem: Sticky type checking is more annoying than useful.
Solution: Remove the error for changing a variable type.
Files: src/eval.c, src/testdir/test_assign.vim,
src/testdir/test_alot.vim, runtime/doc/eval.txt
*** ../vim-7.4.1545/src/eval.c 2016-03-12 15:22:50.410535232 +0100
--- src/eval.c 2016-03-12 18:54:37.146859030 +0100
***************
*** 22091,22112 ****
if (var_check_ro(v->di_flags, name, FALSE)
|| tv_check_lock(v->di_tv.v_lock, name, FALSE))
return;
- if (v->di_tv.v_type != tv->v_type
- && !((v->di_tv.v_type == VAR_STRING
- || v->di_tv.v_type == VAR_NUMBER)
- && (tv->v_type == VAR_STRING
- || tv->v_type == VAR_NUMBER))
- #ifdef FEAT_FLOAT
- && !((v->di_tv.v_type == VAR_NUMBER
- || v->di_tv.v_type == VAR_FLOAT)
- && (tv->v_type == VAR_NUMBER
- || tv->v_type == VAR_FLOAT))
- #endif
- )
- {
- EMSG2(_("E706: Variable type mismatch for: %s"), name);
- return;
- }
/*
* Handle setting internal v: variables separately where needed to
--- 22091,22096 ----
*** ../vim-7.4.1545/src/testdir/test_assign.vim 2016-03-12 19:02:19.518044054
+0100
--- src/testdir/test_assign.vim 2016-03-12 18:59:21.815894278 +0100
***************
*** 0 ****
--- 1,9 ----
+ " Test for assignment
+
+ func Test_no_type_checking()
+ let v = 1
+ let v = [1,2,3]
+ let v = {'a': 1, 'b': 2}
+ let v = 3.4
+ let v = 'hello'
+ endfunc
*** ../vim-7.4.1545/src/testdir/test_alot.vim 2016-03-10 22:19:40.880775414
+0100
--- src/testdir/test_alot.vim 2016-03-12 18:58:24.180494454 +0100
***************
*** 1,6 ****
--- 1,7 ----
" A series of tests that can run in one Vim invocation.
" This makes testing go faster, since Vim doesn't need to restart.
+ source test_assign.vim
source test_backspace_opt.vim
source test_cursor_func.vim
source test_delete.vim
*** ../vim-7.4.1545/runtime/doc/eval.txt 2016-03-12 15:22:50.414535191
+0100
--- runtime/doc/eval.txt 2016-03-12 19:00:27.671208554 +0100
***************
*** 102,125 ****
"foo" is converted to 0, which means FALSE. To test for a non-empty string,
use empty(): >
:if !empty("foo")
! < *E745* *E728* *E703* *E729* *E730* *E731*
! List, Dictionary and Funcref types are not automatically converted.
*E805* *E806* *E808*
When mixing Number and Float the Number is converted to Float.
Otherwise
there is no automatic conversion of Float. You can use str2float() for String
to Float, printf() for Float to String and float2nr() for Float to Number.
! *E706* *sticky-type-checking*
! You will get an error if you try to change the type of a variable. You need
! to |:unlet| it first to avoid this error. String and Number are considered
! equivalent though, as well are Float and Number. Consider this sequence of
! commands: >
! :let l = "string"
! :let l = 44 " changes type from String to Number
! :let l = [1, 2, 3] " error! l is still a Number
! :let l = 4.4 " changes type from Number to Float
! :let l = "string" " error!
1.2 Function references ~
--- 101,120 ----
"foo" is converted to 0, which means FALSE. To test for a non-empty string,
use empty(): >
:if !empty("foo")
! <
! *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913*
! List, Dictionary, Funcref and Job types are not automatically converted.
*E805* *E806* *E808*
When mixing Number and Float the Number is converted to Float.
Otherwise
there is no automatic conversion of Float. You can use str2float() for String
to Float, printf() for Float to String and float2nr() for Float to Number.
! *E891* *E892* *E893* *E894* *E907* *E911* *E914*
! When expecting a Float a Number can also be used, but nothing else.
!
! *no-type-checking*
! You will not get an error if you try to change the type of a variable.
1.2 Function references ~
*** ../vim-7.4.1545/src/version.c 2016-03-12 16:28:13.885691425 +0100
--- src/version.c 2016-03-12 19:02:01.430232366 +0100
***************
*** 745,746 ****
--- 745,748 ----
{ /* Add new patch number below this line */
+ /**/
+ 1546,
/**/
--
The startling truth finally became apparent, and it was this: Numbers
written on restaurant checks within the confines of restaurants do not follow
the same mathematical laws as numbers written on any other pieces of paper in
any other parts of the Universe. This single statement took the scientific
world by storm. So many mathematical conferences got held in such good
restaurants that many of the finest minds of a generation died of obesity and
heart failure, and the science of mathematics was put back by years.
-- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.