From 15237c8404dd2512cd272804ff4f3d4706123ae7 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 14 Dec 2020 15:10:00 +0000 Subject: [PATCH] Disable the type `byte` --- Changelog.md | 1 + docs/080-breaking-changes.rst | 2 ++ docs/assembly.rst | 2 +- docs/control-structures.rst | 2 +- docs/grammar/SolidityLexer.g4 | 5 ++--- docs/types/reference-types.rst | 2 +- docs/types/value-types.rst | 4 +++- liblangutil/Token.h | 2 +- 8 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Changelog.md b/Changelog.md index 7bbb9e64c..76ddbdcaa 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,7 @@ Breaking Changes: * Standard JSON: Remove the ``legacyAST`` option. * Type Checker: Function call options can only be given once. * Type System: Declarations with the name ``this``, ``super`` and ``_`` are disallowed, with the exception of public functions and events. + * Type System: Disallow the ``byte`` type. It was an alias to ``bytes1``. * Type System: Disallow ``msg.data`` in ``receive()`` function. * Type System: Disallow ``type(super)``. * Type System: Disallow enums with more than 256 members. diff --git a/docs/080-breaking-changes.rst b/docs/080-breaking-changes.rst index 4ac937ec5..e5a4b027c 100644 --- a/docs/080-breaking-changes.rst +++ b/docs/080-breaking-changes.rst @@ -50,6 +50,8 @@ the compiler notifying you about it. in all branches of the evaluation tree. Now, if constant variables are used as intermediate expressions, their values will be properly rounded in the same way as when they are used in run-time expressions. +* The type ``byte`` has been removed. It was an alias of ``bytes1``. + New Restrictions ================ diff --git a/docs/assembly.rst b/docs/assembly.rst index 2b5731cbc..d5d73cfb1 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -159,7 +159,7 @@ Local Solidity variables are available for assignments, for example: .. warning:: If you access variables of a type that spans less than 256 bits - (for example ``uint64``, ``address``, ``bytes16`` or ``byte``), + (for example ``uint64``, ``address``, or ``bytes16``), you cannot make any assumptions about bits not part of the encoding of the type. Especially, do not assume them to be zero. To be safe, always clear the data properly before you use it diff --git a/docs/control-structures.rst b/docs/control-structures.rst index ccde0e1b0..76f2a7497 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -261,7 +261,7 @@ which only need to be created if there is a dispute. // can be pre-computed. It is just there for illustration. // You actually only need ``new D{salt: salt}(arg)``. address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( - byte(0xff), + bytes1(0xff), address(this), salt, keccak256(abi.encodePacked( diff --git a/docs/grammar/SolidityLexer.g4 b/docs/grammar/SolidityLexer.g4 index 88a8611c0..d8e89b278 100644 --- a/docs/grammar/SolidityLexer.g4 +++ b/docs/grammar/SolidityLexer.g4 @@ -4,7 +4,7 @@ lexer grammar SolidityLexer; * Keywords reserved for future use in Solidity. */ ReservedKeywords: - 'after' | 'alias' | 'apply' | 'auto' | 'case' | 'copyof' | 'default' | 'define' | 'final' + 'after' | 'alias' | 'apply' | 'auto' | 'byte' | 'case' | 'copyof' | 'default' | 'define' | 'final' | 'implements' | 'in' | 'inline' | 'let' | 'macro' | 'match' | 'mutable' | 'null' | 'of' | 'partial' | 'promise' | 'reference' | 'relocatable' | 'sealed' | 'sizeof' | 'static' | 'supports' | 'switch' | 'typedef' | 'typeof' | 'var'; @@ -37,10 +37,9 @@ Fixed: 'fixed' | ('fixed' [1-9][0-9]* 'x' [1-9][0-9]*); From: 'from'; /** * Bytes types of fixed length. - * byte is an alias of bytes1. */ FixedBytes: - 'byte' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | + 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | 'bytes17' | 'bytes18' | 'bytes19' | 'bytes20' | 'bytes21' | 'bytes22' | 'bytes23' | 'bytes24' | 'bytes25' | 'bytes26' | 'bytes27' | 'bytes28' | 'bytes29' | 'bytes30' | 'bytes31' | 'bytes32'; diff --git a/docs/types/reference-types.rst b/docs/types/reference-types.rst index 419d5dfc5..897539468 100644 --- a/docs/types/reference-types.rst +++ b/docs/types/reference-types.rst @@ -391,7 +391,7 @@ Array Members // Create a dynamic byte array: bytes memory b = new bytes(200); for (uint i = 0; i < b.length; i++) - b[i] = byte(uint8(i)); + b[i] = bytes1(uint8(i)); return b; } } diff --git a/docs/types/value-types.rst b/docs/types/value-types.rst index 0905820aa..3f74a7f5d 100644 --- a/docs/types/value-types.rst +++ b/docs/types/value-types.rst @@ -369,7 +369,6 @@ Fixed-size byte arrays The value types ``bytes1``, ``bytes2``, ``bytes3``, ..., ``bytes32`` hold a sequence of bytes from one to up to 32. -``byte`` is an alias for ``bytes1``. Operators: @@ -391,6 +390,9 @@ Members: 31 bytes of space for each element (except in storage). It is better to use the ``bytes`` type instead. +.. note:: + Prior to version 0.8.0, ``byte`` used to be an alias for ``bytes1``. + Dynamically-sized byte array ---------------------------- diff --git a/liblangutil/Token.h b/liblangutil/Token.h index 2eb97054e..13f836589 100644 --- a/liblangutil/Token.h +++ b/liblangutil/Token.h @@ -212,7 +212,6 @@ namespace solidity::langutil K(Int, "int", 0) \ K(UInt, "uint", 0) \ K(Bytes, "bytes", 0) \ - K(Byte, "byte", 0) \ K(String, "string", 0) \ K(Address, "address", 0) \ K(Bool, "bool", 0) \ @@ -242,6 +241,7 @@ namespace solidity::langutil K(Alias, "alias", 0) \ K(Apply, "apply", 0) \ K(Auto, "auto", 0) \ + K(Byte, "byte", 0) \ K(Case, "case", 0) \ K(CopyOf, "copyof", 0) \ K(Default, "default", 0) \