diff options
| author | Li Jin <dragon-fly@qq.com> | 2021-08-19 00:14:08 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2021-08-19 00:14:08 +0800 |
| commit | eb4c34ed2ff266877e90749afa512391e470321b (patch) | |
| tree | b22fc74c288a68d0c85b9b8b03ec58602798a72c /src/yuescript/yue_compiler.cpp | |
| parent | 38908616d0e08b72e6b00d18490ed917fa643e4f (diff) | |
| download | yuescript-eb4c34ed2ff266877e90749afa512391e470321b.tar.gz yuescript-eb4c34ed2ff266877e90749afa512391e470321b.tar.bz2 yuescript-eb4c34ed2ff266877e90749afa512391e470321b.zip | |
fix a missed case for issue #64.v0.8.1
Diffstat (limited to '')
| -rwxr-xr-x[-rw-r--r--] | src/yuescript/yue_compiler.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index e404cd4..f2a0b8c 100644..100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -56,7 +56,7 @@ using namespace parserlib; | |||
| 56 | 56 | ||
| 57 | typedef std::list<std::string> str_list; | 57 | typedef std::list<std::string> str_list; |
| 58 | 58 | ||
| 59 | const std::string_view version = "0.8.0"sv; | 59 | const std::string_view version = "0.8.1"sv; |
| 60 | const std::string_view extension = "yue"sv; | 60 | const std::string_view extension = "yue"sv; |
| 61 | 61 | ||
| 62 | class YueCompilerImpl { | 62 | class YueCompilerImpl { |
| @@ -1671,6 +1671,36 @@ private: | |||
| 1671 | } | 1671 | } |
| 1672 | case id<default_pair_t>() : { | 1672 | case id<default_pair_t>() : { |
| 1673 | auto dp = static_cast<default_pair_t*>(pair); | 1673 | auto dp = static_cast<default_pair_t*>(pair); |
| 1674 | if (auto exp = dp->key.as<Exp_t>()) { | ||
| 1675 | ++index; | ||
| 1676 | if (!isAssignable(static_cast<Exp_t*>(exp))) { | ||
| 1677 | throw std::logic_error(_info.errorMessage("can't destructure value"sv, exp)); | ||
| 1678 | } | ||
| 1679 | auto value = singleValueFrom(exp); | ||
| 1680 | auto item = value->item.get(); | ||
| 1681 | if (ast_is<simple_table_t>(item) || | ||
| 1682 | item->getByPath<TableLit_t>()) { | ||
| 1683 | throw std::logic_error(_info.errorMessage("invalid use of default value"sv, dp->defVal)); | ||
| 1684 | } else { | ||
| 1685 | bool lintGlobal = _config.lintGlobalVariable; | ||
| 1686 | _config.lintGlobalVariable = false; | ||
| 1687 | auto varName = singleVariableFrom(exp); | ||
| 1688 | bool isVariable = !varName.empty(); | ||
| 1689 | if (!isVariable) { | ||
| 1690 | str_list temp; | ||
| 1691 | transformExp(exp, temp, ExpUsage::Closure); | ||
| 1692 | varName = std::move(temp.back()); | ||
| 1693 | } | ||
| 1694 | _config.lintGlobalVariable = lintGlobal; | ||
| 1695 | pairs.push_back({ | ||
| 1696 | isVariable, | ||
| 1697 | varName, | ||
| 1698 | '[' + std::to_string(index) + ']', | ||
| 1699 | dp->defVal | ||
| 1700 | }); | ||
| 1701 | } | ||
| 1702 | break; | ||
| 1703 | } | ||
| 1674 | std::string keyName, valueStr; | 1704 | std::string keyName, valueStr; |
| 1675 | if (dp->key) { | 1705 | if (dp->key) { |
| 1676 | auto key = dp->key->getByPath<Name_t>(); | 1706 | auto key = dp->key->getByPath<Name_t>(); |
| @@ -1679,8 +1709,7 @@ private: | |||
| 1679 | if (!dp->value) valueStr = keyName; | 1709 | if (!dp->value) valueStr = keyName; |
| 1680 | if (Keywords.find(keyName) != Keywords.end()) { | 1710 | if (Keywords.find(keyName) != Keywords.end()) { |
| 1681 | keyName = "[\""s + keyName + "\"]"s; | 1711 | keyName = "[\""s + keyName + "\"]"s; |
| 1682 | } | 1712 | } else { |
| 1683 | else { | ||
| 1684 | keyName = "."s + keyName; | 1713 | keyName = "."s + keyName; |
| 1685 | } | 1714 | } |
| 1686 | } | 1715 | } |
