Skip to content

Commit 0a14368

Browse files
committed
Display human readable type name in conversion error message
1 parent d4e2c2c commit 0a14368

File tree

70 files changed

+610
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+610
-93
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Compiler Features:
99
* Yul Optimizer: Add rule to convert `mod(mul(X, Y), A)` into `mulmod(X, Y, A)`, if `A` is a power of two.
1010
* Yul Optimizer: Add rule to convert `mod(add(X, Y), A)` into `addmod(X, Y, A)`, if `A` is a power of two.
1111
* Code Generator: More efficient code for checked addition and subtraction.
12+
* Error Reporter: More readable and informative error/warning messages.
1213

1314
Bugfixes:
1415
* Commandline Interface: Disallow the following options outside of the compiler mode: ``--via-ir``,``--metadata-literal``, ``--metadata-hash``, ``--model-checker-show-unproved``, ``--model-checker-div-mod-no-slacks``, ``--model-checker-engine``, ``--model-checker-invariants``, ``--model-checker-solvers``, ``--model-checker-timeout``, ``--model-checker-contracts``, ``--model-checker-targets``.

libsolidity/analysis/TypeChecker.cpp

Lines changed: 51 additions & 51 deletions
Large diffs are not rendered by default.

libsolidity/ast/Types.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,24 @@ string ArrayType::toString(bool _short) const
18081808
return ret;
18091809
}
18101810

1811+
string ArrayType::humanReadableName() const
1812+
{
1813+
string ret;
1814+
if (isString())
1815+
ret = "string";
1816+
else if (isByteArrayOrString())
1817+
ret = "bytes";
1818+
else
1819+
{
1820+
ret = baseType()->toString(true) + "[";
1821+
if (!isDynamicallySized())
1822+
ret += length().str();
1823+
ret += "]";
1824+
}
1825+
ret += " " + stringForReferencePart();
1826+
return ret;
1827+
}
1828+
18111829
string ArrayType::canonicalName() const
18121830
{
18131831
string ret;
@@ -1995,6 +2013,11 @@ string ArraySliceType::toString(bool _short) const
19952013
return m_arrayType.toString(_short) + " slice";
19962014
}
19972015

2016+
string ArraySliceType::humanReadableName() const
2017+
{
2018+
return m_arrayType.humanReadableName() + " slice";
2019+
}
2020+
19982021
Type const* ArraySliceType::mobileType() const
19992022
{
20002023
if (
@@ -2670,6 +2693,17 @@ string TupleType::toString(bool _short) const
26702693
return str + ")";
26712694
}
26722695

2696+
string TupleType::humanReadableName() const
2697+
{
2698+
if (components().empty())
2699+
return "tuple()";
2700+
string str = "tuple(";
2701+
for (auto const& t: components())
2702+
str += (t ? t->humanReadableName() : "") + ",";
2703+
str.pop_back();
2704+
return str + ")";
2705+
}
2706+
26732707
u256 TupleType::storageSize() const
26742708
{
26752709
solAssert(false, "Storage size of non-storable tuple type requested.");

libsolidity/ast/Types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ class ArrayType: public ReferenceType
833833
bool nameable() const override { return true; }
834834

835835
std::string toString(bool _short) const override;
836+
std::string humanReadableName() const override;
836837
std::string canonicalName() const override;
837838
std::string signatureInExternalFunction(bool _structsByName) const override;
838839
MemberList::MemberMap nativeMembers(ASTNode const* _currentScope) const override;
@@ -897,6 +898,7 @@ class ArraySliceType: public ReferenceType
897898
bool isDynamicallySized() const override { return true; }
898899
bool isDynamicallyEncoded() const override { return true; }
899900
std::string toString(bool _short) const override;
901+
std::string humanReadableName() const override;
900902
Type const* mobileType() const override;
901903

902904
BoolResult validForLocation(DataLocation _loc) const override { return m_arrayType.validForLocation(_loc); }
@@ -1177,7 +1179,8 @@ class TupleType: public CompositeType
11771179
std::string richIdentifier() const override;
11781180
bool operator==(Type const& _other) const override;
11791181
TypeResult binaryOperatorResult(Token, Type const*) const override { return nullptr; }
1180-
std::string toString(bool) const override;
1182+
std::string toString(bool _short) const override;
1183+
std::string humanReadableName() const override;
11811184
bool canBeStored() const override { return false; }
11821185
u256 storageSize() const override;
11831186
bool hasSimpleZeroValueInMemory() const override { return false; }

test/libsolidity/syntaxTests/abiEncoder/v1_call_to_v2_constructor_accepting_struct.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ contract Test {
1818
}
1919
}
2020
// ----
21-
// TypeError 2443: (B:91-100): The type of this parameter, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
21+
// TypeError 2443: (B:91-100): The type of this parameter, struct C.Item memory, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.

test/libsolidity/syntaxTests/abiEncoder/v1_call_to_v2_contract_function_accepting_struct_via_named_argument.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ contract Test {
1818
}
1919
}
2020
// ----
21-
// TypeError 2443: (B:119-129): The type of this parameter, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
21+
// TypeError 2443: (B:119-129): The type of this parameter, struct C.Item memory, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.

test/libsolidity/syntaxTests/abiEncoder/v1_call_to_v2_contract_function_pointer_accepting_struct.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ contract Test {
2020
}
2121
}
2222
// ----
23-
// TypeError 2443: (B:166-175): The type of this parameter, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
23+
// TypeError 2443: (B:166-175): The type of this parameter, struct C.Item memory, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.

test/libsolidity/syntaxTests/abiEncoder/v1_call_to_v2_contract_function_returning_dynamic_string_array.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ contract D {
1414
}
1515
}
1616
// ----
17-
// TypeError 2428: (B:85-105): The type of return parameter 1, string[], is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
17+
// TypeError 2428: (B:85-105): The type of return parameter 1, string[] memory, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.

test/libsolidity/syntaxTests/abiEncoder/v1_call_to_v2_contract_function_returning_struct.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ contract Test {
1818
}
1919
}
2020
// ----
21-
// TypeError 2428: (B:90-112): The type of return parameter 1, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
21+
// TypeError 2428: (B:90-112): The type of return parameter 1, struct C.Item memory, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.

test/libsolidity/syntaxTests/abiEncoder/v1_call_to_v2_contract_function_returning_struct_with_dynamic_array.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ contract Test {
1818
}
1919
}
2020
// ----
21-
// TypeError 2428: (B:90-112): The type of return parameter 1, struct C.Item, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.
21+
// TypeError 2428: (B:90-112): The type of return parameter 1, struct C.Item memory, is only supported in ABI coder v2. Use "pragma abicoder v2;" to enable the feature.

0 commit comments

Comments
 (0)