Skip to content

Commit

Permalink
Tests checking outputs produced in presence of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cameel committed Jun 15, 2023
1 parent 374a6fd commit f50820f
Show file tree
Hide file tree
Showing 20 changed files with 602 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--allow-paths .
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity *;

contract C {
// This will trigger a fatal error at the analysis stage, of the kind that terminates analysis
// immediately without letting the current step finish.
constructor(uint[] storage) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_outputs_on_analysis_error_fatal/in.sol"]}
},
"settings": {
"outputSelection": {
"*": {
"*": ["*"],
"": ["*"]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"errors":
[
{
"component": "general",
"errorCode": "3644",
"formattedMessage": "TypeError: This parameter has a type that can only be used internally. You can make the contract abstract to avoid this problem.
--> C:7:17:
|
7 | constructor(uint[] storage) {}
| ^^^^^^^^^^^^^^

",
"message": "This parameter has a type that can only be used internally. You can make the contract abstract to avoid this problem.",
"severity": "error",
"sourceLocation":
{
"end": 258,
"file": "C",
"start": 244
},
"type": "TypeError"
}
],
"sources": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--allow-paths .
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity *;

// This will trigger a fatal error at the analysis stage, of the kind that lets the current
// analysis steps finish but terminates analysis after immediately after that step.
function f(uint immutable x) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_outputs_on_analysis_error_fatal_after_current_step/in.sol"]}
},
"settings": {
"outputSelection": {
"*": {
"*": ["*"],
"": ["*"]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"errors":
[
{
"component": "general",
"errorCode": "8297",
"formattedMessage": "DeclarationError: The \"immutable\" keyword can only be used for state variables.
--> C:6:12:
|
6 | function f(uint immutable x) {}
| ^^^^^^^^^^^^^^^^

",
"message": "The \"immutable\" keyword can only be used for state variables.",
"severity": "error",
"sourceLocation":
{
"end": 259,
"file": "C",
"start": 243
},
"type": "DeclarationError"
}
],
"sources":
{
"C":
{
"ast":
{
"absolutePath": "C",
"exportedSymbols":
{
"f":
[
7
]
},
"id": 8,
"license": "GPL-3.0",
"nodeType": "SourceUnit",
"nodes":
[
{
"id": 1,
"literals":
[
"solidity",
"*"
],
"nodeType": "PragmaDirective",
"src": "36:18:0"
},
{
"body":
{
"id": 6,
"nodeType": "Block",
"src": "261:2:0",
"statements": []
},
"id": 7,
"implemented": true,
"kind": "freeFunction",
"modifiers": [],
"name": "f",
"nameLocation": "241:1:0",
"nodeType": "FunctionDefinition",
"parameters":
{
"id": 4,
"nodeType": "ParameterList",
"parameters":
[
{
"constant": false,
"id": 3,
"mutability": "immutable",
"name": "x",
"nameLocation": "258:1:0",
"nodeType": "VariableDeclaration",
"scope": 7,
"src": "243:16:0",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName":
{
"id": 2,
"name": "uint",
"nodeType": "ElementaryTypeName",
"src": "243:4:0",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"visibility": "internal"
}
],
"src": "242:18:0"
},
"returnParameters":
{
"id": 5,
"nodeType": "ParameterList",
"parameters": [],
"src": "261:0:0"
},
"scope": 8,
"src": "232:31:0",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "internal"
}
],
"src": "36:228:0"
},
"id": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--allow-paths .
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity *;

contract C {
// This will trigger a non-fatal error at the analysis stage.
// With this kind of error we still run subsequent analysis stages.
uint x;
string y = x;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_outputs_on_analysis_error_non_fatal/in.sol"]}
},
"settings": {
"outputSelection": {
"*": {
"*": ["*"],
"": ["*"]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"errors":
[
{
"component": "general",
"errorCode": "7407",
"formattedMessage": "TypeError: Type uint256 is not implicitly convertible to expected type string storage ref.
--> C:8:16:
|
8 | string y = x;
| ^

",
"message": "Type uint256 is not implicitly convertible to expected type string storage ref.",
"severity": "error",
"sourceLocation":
{
"end": 235,
"file": "C",
"start": 234
},
"type": "TypeError"
}
],
"sources": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--allow-paths .
13 changes: 13 additions & 0 deletions test/cmdlineTests/standard_outputs_on_compilation_error/in.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity *;

contract C {
// This will trigger an error at the compilation stage.
// CodeGenerationError due to immutable initialization in constructor being optimized out.
uint immutable public x;

constructor() {
x = 0;
while (true) {}
}
}
15 changes: 15 additions & 0 deletions test/cmdlineTests/standard_outputs_on_compilation_error/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_outputs_on_compilation_error/in.sol"]}
},
"settings": {
"optimizer": {"enabled": true},
"outputSelection": {
"*": {
"*": ["*"],
"": ["*"]
}
}
}
}
Loading

0 comments on commit f50820f

Please sign in to comment.