Skip to content

Commit 27590ee

Browse files
authored
Fix shadowing issue in sema.h (#1127)
1 parent 66c3b3e commit 27590ee

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

source/sema.h

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,11 +1511,15 @@ class sema
15111511
)
15121512
-> bool
15131513
{
1514-
std::vector<error_entry> devnull;
1515-
auto& errors = emit_errors ? this->errors : devnull;
1514+
const std::function emit_error = [this](source_position pos, std::string_view msg) {
1515+
errors.emplace_back(pos, msg);
1516+
};
1517+
const std::function skip_error = [](source_position, std::string_view){};
1518+
1519+
const auto handle_error = emit_errors ? emit_error : skip_error;
15161520

15171521
if (n.has_name("operator")) {
1518-
errors.emplace_back(
1522+
handle_error(
15191523
n.position(),
15201524
"the name 'operator' is incomplete - did you mean to write an overloaded operator name like 'operator*' or 'operator++'?"
15211525
);
@@ -1529,7 +1533,7 @@ class sema
15291533
&& !n.has_initializer()
15301534
)
15311535
{
1532-
errors.emplace_back(
1536+
handle_error(
15331537
n.position(),
15341538
"an object with a deduced type must have an = initializer"
15351539
);
@@ -1543,7 +1547,7 @@ class sema
15431547
&& !n.initializer->is_expression()
15441548
)
15451549
{
1546-
errors.emplace_back(
1550+
handle_error(
15471551
n.position(),
15481552
"an object initializer must be an expression"
15491553
);
@@ -1559,7 +1563,7 @@ class sema
15591563
)
15601564
)
15611565
{
1562-
errors.emplace_back(
1566+
handle_error(
15631567
n.position(),
15641568
"a namespace must be = initialized with a { } body containing declarations"
15651569
);
@@ -1573,7 +1577,7 @@ class sema
15731577
&& n.initializer->is_return()
15741578
)
15751579
{
1576-
errors.emplace_back(
1580+
handle_error(
15771581
n.position(),
15781582
"a function with a single-expression body doesn't need to say 'return' - either omit 'return' or write a full { }-enclosed function body"
15791583
);
@@ -1588,7 +1592,7 @@ class sema
15881592
&& !n.has_initializer()
15891593
)
15901594
{
1591-
errors.emplace_back(
1595+
handle_error(
15921596
n.position(),
15931597
"a function must have a body ('=' initializer), unless it is virtual (has a 'virtual this' parameter) or is defaultable (operator== or operator<=>)"
15941598
);
@@ -1601,7 +1605,7 @@ class sema
16011605
&& !n.parent_is_type()
16021606
)
16031607
{
1604-
errors.emplace_back(
1608+
handle_error(
16051609
n.position(),
16061610
"(temporary alpha limitation) a type must be in a namespace or type scope - function-local types are not yet supported"
16071611
);
@@ -1614,7 +1618,7 @@ class sema
16141618
&& n.has_wildcard_type()
16151619
)
16161620
{
1617-
errors.emplace_back(
1621+
handle_error(
16181622
n.position(),
16191623
"a type scope variable must have a declared type"
16201624
);
@@ -1632,7 +1636,7 @@ class sema
16321636
)
16331637
)
16341638
{
1635-
errors.emplace_back(
1639+
handle_error(
16361640
n.identifier->position(),
16371641
"'this' may only be declared as an ordinary function parameter or type-scope (base) object"
16381642
);
@@ -1646,14 +1650,14 @@ class sema
16461650

16471651
if (this_index >= 0) {
16481652
if (!n.parent_is_type()) {
1649-
errors.emplace_back(
1653+
handle_error(
16501654
n.position(),
16511655
"'this' must be the first parameter of a type-scope function"
16521656
);
16531657
return false;
16541658
}
16551659
if (this_index != 0) {
1656-
errors.emplace_back(
1660+
handle_error(
16571661
n.position(),
16581662
"'this' must be the first parameter"
16591663
);
@@ -1663,14 +1667,14 @@ class sema
16631667

16641668
if (that_index >= 0) {
16651669
if (!n.parent_is_type()) {
1666-
errors.emplace_back(
1670+
handle_error(
16671671
n.position(),
16681672
"'that' must be the second parameter of a type-scope function"
16691673
);
16701674
return false;
16711675
}
16721676
if (that_index != 1) {
1673-
errors.emplace_back(
1677+
handle_error(
16741678
n.position(),
16751679
"'that' must be the second parameter"
16761680
);
@@ -1685,7 +1689,7 @@ class sema
16851689
&& n.parent_is_namespace()
16861690
)
16871691
{
1688-
errors.emplace_back(
1692+
handle_error(
16891693
n.identifier->position(),
16901694
"namespace scope objects must have a concrete type, not a deduced type"
16911695
);
@@ -1699,7 +1703,7 @@ class sema
16991703
&& !n.is_object_alias()
17001704
)
17011705
{
1702-
errors.emplace_back(
1706+
handle_error(
17031707
n.identifier->position(),
17041708
"'_' (wildcard) may not be the name of a function or type - it may only be used as the name of an anonymous object, object alias, or namespace"
17051709
);
@@ -1712,7 +1716,7 @@ class sema
17121716
)
17131717
{
17141718
if (!n.is_object()) {
1715-
errors.emplace_back(
1719+
handle_error(
17161720
n.position(),
17171721
"a member named 'this' declares a base subobject, and must be followed by a base type name"
17181722
);
@@ -1724,7 +1728,7 @@ class sema
17241728
&& !n.is_default_access()
17251729
)
17261730
{
1727-
errors.emplace_back(
1731+
handle_error(
17281732
n.position(),
17291733
"a base type must be public (the default)"
17301734
);
@@ -1733,7 +1737,7 @@ class sema
17331737

17341738
if (n.has_wildcard_type())
17351739
{
1736-
errors.emplace_back(
1740+
handle_error(
17371741
n.position(),
17381742
"a base type must be a specific type, not a deduced type (omitted or '_'-wildcarded)"
17391743
);
@@ -1746,7 +1750,7 @@ class sema
17461750
&& !n.parent_is_type()
17471751
)
17481752
{
1749-
errors.emplace_back(
1753+
handle_error(
17501754
n.position(),
17511755
"an access-specifier is only allowed on a type-scope (member) declaration"
17521756
);
@@ -1761,7 +1765,7 @@ class sema
17611765
&& (*func->parameters)[0]->has_name("this")
17621766
);
17631767
if ((*func->parameters)[0]->is_polymorphic()) {
1764-
errors.emplace_back(
1768+
handle_error(
17651769
n.position(),
17661770
"a constructor may not be declared virtual, override, or final"
17671771
);
@@ -1777,7 +1781,7 @@ class sema
17771781
{
17781782
assert (n.identifier->get_token());
17791783
auto name = n.identifier->get_token()->to_string();
1780-
errors.emplace_back(
1784+
handle_error(
17811785
n.position(),
17821786
"(temporary alpha limitation) local functions like '" + name + ": (/*params*/) = {/*body*/}' are not currently supported - write a local variable initialized with an unnamed function like '" + name + " := :(/*params*/) = {/*body*/};' instead (add '=' and ';')"
17831787
);
@@ -1796,7 +1800,7 @@ class sema
17961800
)
17971801
)
17981802
{
1799-
errors.emplace_back(
1803+
handle_error(
18001804
n.position(),
18011805
"overloading '" + n.name()->to_string() + "' is not allowed"
18021806
);
@@ -1824,7 +1828,7 @@ class sema
18241828
)
18251829
)
18261830
{
1827-
errors.emplace_back(
1831+
handle_error(
18281832
n.position(),
18291833
n.name()->to_string() + " must have 'this' as the first parameter"
18301834
);
@@ -1861,7 +1865,7 @@ class sema
18611865
// ... and if it isn't that, then complain
18621866
else
18631867
{
1864-
errors.emplace_back(
1868+
handle_error(
18651869
params[0]->position(),
18661870
"'main' must be declared as 'main: ()' with zero parameters, or 'main: (args)' with one parameter named 'args' for which the type 'std::vector<std::string_view>' will be deduced"
18671871
);
@@ -1873,7 +1877,7 @@ class sema
18731877
{
18741878
if (!n.is_function())
18751879
{
1876-
errors.emplace_back(
1880+
handle_error(
18771881
n.position(),
18781882
"'operator=' must be a function"
18791883
);
@@ -1883,7 +1887,7 @@ class sema
18831887

18841888
if (func->has_declared_return_type())
18851889
{
1886-
errors.emplace_back(
1890+
handle_error(
18871891
func->parameters->parameters[0]->position(),
18881892
"'operator=' may not have a declared return type"
18891893
);
@@ -1892,7 +1896,7 @@ class sema
18921896

18931897
if (func->parameters->ssize() == 0)
18941898
{
1895-
errors.emplace_back(
1899+
handle_error(
18961900
n.position(),
18971901
"an operator= function must have a parameter"
18981902
);
@@ -1905,7 +1909,7 @@ class sema
19051909
&& (*func->parameters)[0]->pass != passing_style::move
19061910
)
19071911
{
1908-
errors.emplace_back(
1912+
handle_error(
19091913
n.position(),
19101914
"an operator= function's 'this' parameter must be inout, out, or move"
19111915
);
@@ -1919,7 +1923,7 @@ class sema
19191923
&& (*func->parameters)[1]->pass != passing_style::move
19201924
)
19211925
{
1922-
errors.emplace_back(
1926+
handle_error(
19231927
n.position(),
19241928
"an operator= function's 'that' parameter must be in or move"
19251929
);
@@ -1932,7 +1936,7 @@ class sema
19321936
&& (*func->parameters)[0]->pass == passing_style::move
19331937
)
19341938
{
1935-
errors.emplace_back(
1939+
handle_error(
19361940
n.position(),
19371941
"a destructor may not have other parameters besides 'this'"
19381942
);
@@ -1944,7 +1948,7 @@ class sema
19441948
{
19451949
if (decl->has_name("that"))
19461950
{
1947-
errors.emplace_back(
1951+
handle_error(
19481952
n.position(),
19491953
"'that' may not be used as a type scope name"
19501954
);
@@ -1957,7 +1961,7 @@ class sema
19571961
&& !n.has_bool_return_type()
19581962
)
19591963
{
1960-
errors.emplace_back(
1964+
handle_error(
19611965
n.position(),
19621966
n.name()->to_string() + " must return bool"
19631967
);
@@ -1973,7 +1977,7 @@ class sema
19731977
&& return_name.find("partial_ordering") == return_name.npos
19741978
)
19751979
{
1976-
errors.emplace_back(
1980+
handle_error(
19771981
n.position(),
19781982
"operator<=> must return std::strong_ordering, std::weak_ordering, or std::partial_ordering"
19791983
);
@@ -1990,7 +1994,7 @@ class sema
19901994
&& !stmt->is_using()
19911995
)
19921996
{
1993-
errors.emplace_back(
1997+
handle_error(
19941998
stmt->position(),
19951999
"a user-defined type body must contain only declarations or 'using' statements, not other code"
19962000
);

0 commit comments

Comments
 (0)