aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authorVoR0220 <catalanor0220@gmail.com>2016-05-06 06:47:08 +0800
committerVoR0220 <catalanor0220@gmail.com>2016-05-10 00:41:03 +0800
commita6fc3c8f30d987f90d791c6cc5ec9d0a6a132109 (patch)
treeefeb403b50f1569429dbc342415a71ccb78863d2 /libsolidity/analysis
parentbfc238c8d11e118443d373d819deeada9fe1ea3b (diff)
downloaddexon-solidity-a6fc3c8f30d987f90d791c6cc5ec9d0a6a132109.tar
dexon-solidity-a6fc3c8f30d987f90d791c6cc5ec9d0a6a132109.tar.gz
dexon-solidity-a6fc3c8f30d987f90d791c6cc5ec9d0a6a132109.tar.bz2
dexon-solidity-a6fc3c8f30d987f90d791c6cc5ec9d0a6a132109.tar.lz
dexon-solidity-a6fc3c8f30d987f90d791c6cc5ec9d0a6a132109.tar.xz
dexon-solidity-a6fc3c8f30d987f90d791c6cc5ec9d0a6a132109.tar.zst
dexon-solidity-a6fc3c8f30d987f90d791c6cc5ec9d0a6a132109.zip
reorganized tests and fixed mobile types and implicit conversions of rationals and fixed point types
one final tweak check for null types
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp72
1 files changed, 53 insertions, 19 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 1b37d42e..264fee6b 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -774,8 +774,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
solAssert(!var.typeName(), "");
if (
valueComponentType->category() == Type::Category::RationalNumber &&
- !dynamic_pointer_cast<RationalNumberType const>(valueComponentType)->integerType() &&
- !dynamic_pointer_cast<RationalNumberType const>(valueComponentType)->fixedPointType()
+ !dynamic_pointer_cast<RationalNumberType const>(valueComponentType)->mobileType()
)
fatalTypeError(_statement.initialValue()->location(), "Invalid rational " + valueComponentType->toString() + ".");
var.annotation().type = valueComponentType->mobileType();
@@ -785,14 +784,32 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
{
var.accept(*this);
if (!valueComponentType->isImplicitlyConvertibleTo(*var.annotation().type))
- typeError(
- _statement.location(),
- "Type " +
- valueComponentType->toString() +
- " is not implicitly convertible to expected type " +
- var.annotation().type->toString() +
- "."
- );
+ {
+ if (
+ valueComponentType->category() == Type::Category::RationalNumber &&
+ dynamic_pointer_cast<RationalNumberType const>(valueComponentType)->denominator() != 1 &&
+ !!valueComponentType->mobileType()
+ )
+ typeError(
+ _statement.location(),
+ "Type " +
+ valueComponentType->toString() +
+ " is not implicitly convertible to expected type " +
+ var.annotation().type->toString() +
+ ". Try converting to type " +
+ valueComponentType->mobileType()->toString() +
+ " or use an explicit conversion."
+ );
+ else
+ typeError(
+ _statement.location(),
+ "Type " +
+ valueComponentType->toString() +
+ " is not implicitly convertible to expected type " +
+ var.annotation().type->toString() +
+ "."
+ );
+ }
}
}
return false;
@@ -1499,16 +1516,33 @@ Declaration const& TypeChecker::dereference(UserDefinedTypeName const& _typeName
void TypeChecker::expectType(Expression const& _expression, Type const& _expectedType)
{
_expression.accept(*this);
-
if (!type(_expression)->isImplicitlyConvertibleTo(_expectedType))
- typeError(
- _expression.location(),
- "Type " +
- type(_expression)->toString() +
- " is not implicitly convertible to expected type " +
- _expectedType.toString() +
- "."
- );
+ {
+ if (
+ type(_expression)->category() == Type::Category::RationalNumber &&
+ dynamic_pointer_cast<RationalNumberType const>(type(_expression))->denominator() != 1 &&
+ !!type(_expression)->mobileType()
+ )
+ typeError(
+ _expression.location(),
+ "Type " +
+ type(_expression)->toString() +
+ " is not implicitly convertible to expected type " +
+ _expectedType.toString() +
+ ". Try converting to type " +
+ type(_expression)->mobileType()->toString() +
+ " or using an explicit conversion."
+ );
+ else
+ typeError(
+ _expression.location(),
+ "Type " +
+ type(_expression)->toString() +
+ " is not implicitly convertible to expected type " +
+ _expectedType.toString() +
+ "."
+ );
+ }
}
void TypeChecker::requireLValue(Expression const& _expression)