Skip to content

Commit

Permalink
Fix NomicFoundation#1244: Make address payable type only available …
Browse files Browse the repository at this point in the history
…since 0.5.0

And make `transfer()` built-in only available for `address payable` from 0.5.0.
  • Loading branch information
ggiraldez committed Feb 11, 2025
1 parent 2d6a4e5 commit 04b43f4
Show file tree
Hide file tree
Showing 33 changed files with 751 additions and 95 deletions.
15 changes: 11 additions & 4 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -952,10 +952,14 @@ inherit .star_extension
let @elementary.push_end = @elementary.ref
}

@elementary [ElementaryType [AddressType]] {
@elementary [ElementaryType [AddressType . [AddressKeyword] .]] {
let @elementary.symbol = "address"
}

@elementary [ElementaryType [AddressType . [AddressKeyword] [PayableKeyword] .]] {
let @elementary.symbol = "address payable"
}

@elementary [ElementaryType [BoolKeyword]] {
let @elementary.symbol = "bool"
}
Expand Down Expand Up @@ -2139,18 +2143,21 @@ inherit .star_extension
edge call -> member
}

@member [StructMember] {
node @member.def
node @member.typeof
}

@struct [StructDefinition [StructMembers
@member item: [StructMember @type_name [TypeName] @name name: [Identifier]]
]] {
node @member.def
attr (@member.def) node_definition = @name
attr (@member.def) definiens_node = @member

edge @struct.members -> @member.def

edge @type_name.type_ref -> @struct.lexical_scope

node @member.typeof
attr (@member.typeof) push_symbol = "@typeof"

edge @member.def -> @member.typeof
Expand Down Expand Up @@ -2513,7 +2520,7 @@ inherit .star_extension
; These work like `address`, should they should bind to `address`
@expr [Expression [PayableKeyword]] {
node ref
attr (ref) push_symbol = "address"
attr (ref) push_symbol = "address payable"

edge ref -> @expr.lexical_scope
edge @expr.output -> ref
Expand Down
41 changes: 39 additions & 2 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2819,7 +2819,8 @@ codegen_language_macros::compile!(Language(
name = AddressType,
fields = (
address_keyword = Required(AddressKeyword),
payable_keyword = Optional(reference = PayableKeyword)
payable_keyword =
Optional(reference = PayableKeyword, enabled = From("0.5.0"))
)
)
]
Expand Down Expand Up @@ -6208,9 +6209,45 @@ codegen_language_macros::compile!(Language(
return_type = "bool, bytes memory",
enabled = From("0.5.0")
),
BuiltInFunction(name = "transfer", parameters = ["uint256 amount"])
BuiltInFunction(
name = "transfer",
parameters = ["uint256 amount"],
enabled = Till("0.5.0")
)
]
),
BuiltInType(
name = "address payable",
fields = [
BuiltInField(definition = "uint256 balance"),
BuiltInField(definition = "bytes code", enabled = From("0.8.0")),
BuiltInField(definition = "bytes32 codehash", enabled = From("0.8.0"))
],
functions = [
BuiltInFunction(
name = "call",
parameters = ["bytes memory"],
return_type = "bool, bytes memory"
),
BuiltInFunction(
name = "delegatecall",
parameters = ["bytes memory"],
return_type = "bool, bytes memory"
),
BuiltInFunction(
name = "send",
parameters = ["uint256 amount"],
return_type = "bool"
),
BuiltInFunction(
name = "staticcall",
parameters = ["bytes memory"],
return_type = "bool, bytes memory"
),
BuiltInFunction(name = "transfer", parameters = ["uint256 amount"])
],
enabled = From("0.5.0")
),
BuiltInType(
name = "%Array",
fields = [BuiltInField(definition = "uint length")],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 04b43f4

Please sign in to comment.