diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index e9792ddf2..cc28220ca 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -38,10 +38,12 @@ namespace solidity NameAndTypeResolver::NameAndTypeResolver( GlobalContext& _globalContext, + langutil::EVMVersion _evmVersion, map>& _scopes, ErrorReporter& _errorReporter -) : +): m_scopes(_scopes), + m_evmVersion(_evmVersion), m_errorReporter(_errorReporter), m_globalContext(_globalContext) { @@ -324,7 +326,7 @@ bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _res { if (m_scopes.count(&_node)) setScope(&_node); - return ReferencesResolver(m_errorReporter, *this, _resolveInsideCode).resolve(_node); + return ReferencesResolver(m_errorReporter, *this, m_evmVersion, _resolveInsideCode).resolve(_node); } } diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index e5f5774ab..0c4452cde 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -28,6 +28,8 @@ #include #include +#include + #include #include @@ -55,6 +57,7 @@ public: /// are filled during the lifetime of this object. NameAndTypeResolver( GlobalContext& _globalContext, + langutil::EVMVersion _evmVersion, std::map>& _scopes, langutil::ErrorReporter& _errorReporter ); @@ -130,6 +133,7 @@ private: /// Aliases (for example `import "x" as y;`) create multiple pointers to the same scope. std::map>& m_scopes; + langutil::EVMVersion m_evmVersion; DeclarationContainer* m_currentScope = nullptr; langutil::ErrorReporter& m_errorReporter; GlobalContext& m_globalContext; diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index cb6471020..d8627d49d 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -328,7 +328,7 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly) analysisInfo, errorsIgnored, errorTypeForLoose, - yul::EVMDialect::looseAssemblyForEVM(EVMVersion{}), + yul::EVMDialect::looseAssemblyForEVM(m_evmVersion), resolver ).analyze(_inlineAssembly.operations()); return false; diff --git a/libsolidity/analysis/ReferencesResolver.h b/libsolidity/analysis/ReferencesResolver.h index 5631fb801..207eecdda 100644 --- a/libsolidity/analysis/ReferencesResolver.h +++ b/libsolidity/analysis/ReferencesResolver.h @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -52,10 +53,12 @@ public: ReferencesResolver( langutil::ErrorReporter& _errorReporter, NameAndTypeResolver& _resolver, + langutil::EVMVersion _evmVersion, bool _resolveInsideCode = false ): m_errorReporter(_errorReporter), m_resolver(_resolver), + m_evmVersion(_evmVersion), m_resolveInsideCode(_resolveInsideCode) {} @@ -96,6 +99,7 @@ private: langutil::ErrorReporter& m_errorReporter; NameAndTypeResolver& m_resolver; + langutil::EVMVersion m_evmVersion; /// Stack of return parameters. std::vector m_returnParameters; bool const m_resolveInsideCode; diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index fa7c9ec95..c831542ad 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -269,7 +269,7 @@ bool CompilerStack::analyze() noErrors = false; m_globalContext = make_shared(); - NameAndTypeResolver resolver(*m_globalContext, m_scopes, m_errorReporter); + NameAndTypeResolver resolver(*m_globalContext, m_evmVersion, m_scopes, m_errorReporter); for (Source const* source: m_sourceOrder) if (!resolver.registerDeclarations(*source->ast)) return false; diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp index db3b395a5..3ae071929 100644 --- a/test/libsolidity/Assembly.cpp +++ b/test/libsolidity/Assembly.cpp @@ -64,7 +64,7 @@ eth::AssemblyItems compileContract(std::shared_ptr _sourceCode) map> scopes; GlobalContext globalContext; - NameAndTypeResolver resolver(globalContext, scopes, errorReporter); + NameAndTypeResolver resolver(globalContext, dev::test::Options::get().evmVersion(), scopes, errorReporter); solAssert(Error::containsOnlyWarnings(errorReporter.errors()), ""); resolver.registerDeclarations(*sourceUnit); for (ASTPointer const& node: sourceUnit->nodes()) diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp index 551596456..feebcbe37 100644 --- a/test/libsolidity/SolidityExpressionCompiler.cpp +++ b/test/libsolidity/SolidityExpressionCompiler.cpp @@ -118,7 +118,7 @@ bytes compileFirstExpression( ErrorReporter errorReporter(errors); GlobalContext globalContext; map> scopes; - NameAndTypeResolver resolver(globalContext, scopes, errorReporter); + NameAndTypeResolver resolver(globalContext, dev::test::Options::get().evmVersion(), scopes, errorReporter); resolver.registerDeclarations(*sourceUnit); vector inheritanceHierarchy; diff --git a/test/libsolidity/syntaxTests/inlineAssembly/istanbul.sol b/test/libsolidity/syntaxTests/inlineAssembly/istanbul.sol index 3e1a1cd2a..5e6334749 100644 --- a/test/libsolidity/syntaxTests/inlineAssembly/istanbul.sol +++ b/test/libsolidity/syntaxTests/inlineAssembly/istanbul.sol @@ -1,12 +1,12 @@ contract C { - function f() pure external { + function f() pure external returns (uint id) { assembly { - pop(chainid()) + id := chainid() } } - function g() view external { + function g() view external returns (uint sb) { assembly { - pop(selfbalance()) + sb := selfbalance() } } } diff --git a/test/libsolidity/syntaxTests/inlineAssembly/istanbul_on_petersburg.sol b/test/libsolidity/syntaxTests/inlineAssembly/istanbul_on_petersburg.sol new file mode 100644 index 000000000..aa7eb1a8b --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/istanbul_on_petersburg.sol @@ -0,0 +1,17 @@ +contract C { + function f() pure external returns (uint id) { + assembly { + id := chainid() + } + } + function g() view external returns (uint sb) { + assembly { + sb := selfbalance() + } + } +} +// ==== +// EVMVersion: =petersburg +// ---- +// TypeError: (101-110): The "chainid" instruction is only available for Istanbul-compatible VMs (you are currently compiling for "petersburg"). +// TypeError: (215-228): The "selfbalance" instruction is only available for Istanbul-compatible VMs (you are currently compiling for "petersburg").