internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: vyperlang/vyper

Issue:
Types not always enforced on events
Haven't dug deeply on this one but something equivalent to this is compiling for me:

```python
Sale: event({eth_sold: indexed(uint256(wei))})

@public
def logSale(amount: uint256):
   log.Sale(amount)
```


Discussion:
So unit check is missing, right?

Resolving patch:
diff --git a/vyper/parser/events.py b/vyper/parser/events.py
--- a/vyper/parser/events.py
+++ b/vyper/parser/events.py
@@ -58,6 +58,11 @@ def pack_logging_topics(event_id, args, expected_topics, context, pos):
                     size = ['sload', ['sha3_32', value]]
                 topics.append(byte_array_to_num(value, arg, 'uint256', size))
         else:
+            if arg_type != expected_type:
+                raise TypeMismatchException(
+                    f"Invalid type for logging topic, got {arg_type} expected {expected_type}",
+                    value.pos
+                )
             value = unwrap_location(value)
             value = base_type_conversion(value, arg_type, expected_type, pos=code_pos)
             topics.append(value)


Test patch:
diff --git a/tests/parser/features/test_logging.py b/tests/parser/features/test_logging.py
--- a/tests/parser/features/test_logging.py
+++ b/tests/parser/features/test_logging.py
@@ -216,15 +216,20 @@ def foo():
     assert logs[0].args.arg1 == 123
 
 
-def test_event_logging_with_units(get_contract_with_gas_estimation):
+def test_event_logging_with_units(w3, get_contract_with_gas_estimation, get_logs):
     code = """
-MyLog: event({arg1: indexed(int128(wei)), arg2: int128(wei)})
+MyLog: event({arg1: indexed(uint256(wei)), arg2: uint256(wei)})
 
 @public
+@payable
 def foo():
-    log.MyLog(1, 2)
-"""
-    get_contract_with_gas_estimation(code)
+    log.MyLog(msg.value, 2*msg.value)
+    """
+    c = get_contract_with_gas_estimation(code)
+    tx_hash = c.foo(transact={'value': w3.toWei(0.1, 'ether')})
+    logs = get_logs(tx_hash, c, 'MyLog')
+    assert logs[0].args.arg1 == w3.toWei(0.1, 'ether')
+    assert logs[0].args.arg2 == 2 * w3.toWei(0.1, 'ether')
 
 
 def test_event_logging_with_fixed_array_data(w3,
diff --git a/tests/parser/syntax/test_logging.py b/tests/parser/syntax/test_logging.py
--- a/tests/parser/syntax/test_logging.py
+++ b/tests/parser/syntax/test_logging.py
@@ -26,7 +26,14 @@ def foo():
 def foo():
     x: decimal[4]
     log.Bar(x)
+    """,
     """
+Sale: event({eth_sold: indexed(uint256(wei))})
+
+@public
+def logSale(amount: uint256):
+   log.Sale(amount)
+   """
 ]
Repository: vyperlang/vyper

Issue:
Nonsense struct output with inline returns
### Version Information

* vyper Version (output of `vyper --version`): 0.1.0b10
* OS: osx
* Python Version (output of `python --version`): Python 3.7.2
* Environment (output of `pip freeze`): 
```
eth-tester==0.1.0b39
py-evm==0.2.0a42
pytest==5.0.1
vyper==0.1.0b10
web3==5.0.0b2
```

### What's your issue about?

When `@public` functions which return structs are returned inline from other `@public` functions, the output is nonsense values.

In the following code, `wrap_get_my_struct_WORKING` returns the correct data, whereas `wrap_get_my_struct_BROKEN` returns nonsense.

```python
struct MyStruct:
    e1: decimal
    e2: timestamp


# @dev Construct a MyStruct.
@public
@constant
def get_my_struct(_e1: decimal, _e2: timestamp) -> MyStruct:
    return MyStruct({e1: _e1, e2: _e2})
 

# @dev Wrap self.get_my_struct.
@public
@constant
def wrap_get_my_struct_WORKING(_e1: decimal) -> MyStruct:
    testing: MyStruct = self.get_my_struct(_e1, block.timestamp)
    return testing

# @dev Wrap self.get_my_struct.
@public
@constant
def wrap_get_my_struct_BROKEN(_e1: decimal) -> MyStruct:
    return self.get_my_struct(_e1, block.timestamp)
```



Discussion:

Resolving patch:
diff --git a/vyper/parser/parser_utils.py b/vyper/parser/parser_utils.py
--- a/vyper/parser/parser_utils.py
+++ b/vyper/parser/parser_utils.py
@@ -961,7 +961,7 @@ def gen_tuple_return(stmt, context, sub):
     # Is from a call expression.
     if sub.args and len(sub.args[0].args) > 0 and sub.args[0].args[0].value == 'call':
         # self-call to public.
-        mem_pos = sub.args[0].args[-1]
+        mem_pos = sub
         mem_size = get_size_of_type(sub.typ) * 32
         return LLLnode.from_list(['return', mem_pos, mem_size], typ=sub.typ)
 


Test patch:
diff --git a/tests/parser/features/external_contracts/test_self_call_struct.py b/tests/parser/features/external_contracts/test_self_call_struct.py
new file mode 100644
--- /dev/null
+++ b/tests/parser/features/external_contracts/test_self_call_struct.py
@@ -0,0 +1,34 @@
+from decimal import (
+    Decimal,
+)
+
+
+def test_call_to_self_struct(w3, get_contract):
+    code = """
+struct MyStruct:
+    e1: decimal
+    e2: timestamp
+
+@public
+@constant
+def get_my_struct(_e1: decimal, _e2: timestamp) -> MyStruct:
+    return MyStruct({e1: _e1, e2: _e2})
+
+@public
+@constant
+def wrap_get_my_struct_WORKING(_e1: decimal) -> MyStruct:
+    testing: MyStruct = self.get_my_struct(_e1, block.timestamp)
+    return testing
+
+@public
+@constant
+def wrap_get_my_struct_BROKEN(_e1: decimal) -> MyStruct:
+    return self.get_my_struct(_e1, block.timestamp)
+    """
+    c = get_contract(code)
+    assert c.wrap_get_my_struct_WORKING(Decimal('0.1')) == (
+        Decimal('0.1'), w3.eth.getBlock(w3.eth.blockNumber)['timestamp']
+    )
+    assert c.wrap_get_my_struct_BROKEN(Decimal('0.1')) == (
+        Decimal('0.1'), w3.eth.getBlock(w3.eth.blockNumber)['timestamp']
+    )
Repository: vyperlang/vyper

Issue:
Add docs for assert_modifiable

### What's your issue about?

`assert_modifiable` was added in #1480 add docs for it.

### How can it be fixed?

`^.^`



Discussion:

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -103,7 +103,7 @@
 # Add any paths that contain custom static files (such as style sheets) here,
 # relative to this directory. They are copied after the builtin static files,
 # so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ['_static']
+# html_static_path = ['_static']
 
 # Custom sidebar templates, must be a dictionary that maps document names
 # to template names.


Test patch:
Repository: vyperlang/vyper

Issue:
Code that ends in a comment (with no newline) cannot be compiled
This was previously [reported](https://github.com/ethereum/vyper/issues/1161) for Vyper, but it’s actually [a Python bug](https://bugs.python.org/issue35107):

```python
@public
def __init__():
   pass

# BUG (no newline)
```


Discussion:
Can we... Just add an extra beeline before parsing with `ast.parse`?

Resolving patch:
diff --git a/vyper/compiler.py b/vyper/compiler.py
--- a/vyper/compiler.py
+++ b/vyper/compiler.py
@@ -321,7 +321,9 @@ def compile_codes(contract_sources: ContractCodes,
                     interfaces = interfaces[contract_name]
                 out.setdefault(contract_name, {})
                 out[contract_name][output_format] = output_formats_map[output_format](
-                    code=code,
+                    # trailing newline fixes python parsing bug when source ends in a comment
+                    # https://bugs.python.org/issue35107
+                    code=f"{code}\n",
                     contract_name=contract_name,
                     interface_codes=interfaces,
                     source_id=source_id


Test patch:
Repository: vyperlang/vyper

Issue:
AttributeError: 'str' object has no attribute 'fornat' (typo in vyper source)
Same version/environment issue as previous TSTL-discovered bugs.

```
cv0: constant(uint256) = block.difficulty
cv1: constant(uint256) = convert(cv0, uint256)
@public
def f0():
    assert cv0
```

gets:

```
(vyper-venv) cmp3149:vyper adg326$ vyper vfile.9938.vy 
Error compiling: vfile.9938.vy
AttributeError: 'str' object has no attribute 'fornat'
```

The fix is pretty trivial, see the line in `convert.py`:

`vyper/types/convert.py:            raise InvalidLiteralException("Unknown numeric literal type: {}".fornat(in_arg))`

I'll maybe do a tiny PR to fix now.


Discussion:

Resolving patch:
diff --git a/vyper/types/convert.py b/vyper/types/convert.py
--- a/vyper/types/convert.py
+++ b/vyper/types/convert.py
@@ -192,7 +192,7 @@ def to_uint256(expr, args, kwargs, context):
                 pos=getpos(expr)
             )
         else:
-            raise InvalidLiteralException("Unknown numeric literal type: {}".fornat(in_arg))
+            raise InvalidLiteralException("Unknown numeric literal type: {}".format(in_arg))
 
     elif isinstance(in_arg, LLLnode) and input_type == 'int128':
         return LLLnode.from_list(


Test patch:
Repository: vyperlang/vyper

Issue:
Unary subtraction on decimals
### Version Information

* vyper Version: 0.1.0b14

### What's your issue about?

In the release beta 14 release notes it says that unary subtraction on unsigend types is now rejected. However, it also happens for decimals. The following
```
@public
def negation(d: decimal) -> decimal:
   return  -d
```
used to compile before but now doesn't.



Discussion:

Resolving patch:
diff --git a/vyper/parser/expr.py b/vyper/parser/expr.py
--- a/vyper/parser/expr.py
+++ b/vyper/parser/expr.py
@@ -73,9 +73,11 @@
 
 
 def get_min_val_for_type(typ: str) -> int:
-    if "int" not in typ.lower():
-        raise Exception(f"Not an integer type: {typ}")
-    min_val, _, _ = BUILTIN_CONSTANTS['MIN_'+typ.upper()]
+    key = 'MIN_' + typ.upper()
+    try:
+        min_val, _, _ = BUILTIN_CONSTANTS[key]
+    except KeyError as e:
+        raise TypeMismatchException(f"Not a signed type: {typ}") from e
     return min_val
 
 


Test patch:
diff --git a/tests/parser/functions/test_unary.py b/tests/parser/functions/test_unary.py
--- a/tests/parser/functions/test_unary.py
+++ b/tests/parser/functions/test_unary.py
@@ -1,3 +1,7 @@
+from decimal import (
+    Decimal,
+)
+
 import pytest
 
 from vyper.exceptions import (
@@ -31,3 +35,16 @@ def negate(a: int128) -> int128:
     """
     c = get_contract(code)
     assert c.negate(val) == -val
+
+
+decimal_divisor = Decimal('1e10')
+min_decimal = (-2**127 + 1) / decimal_divisor
+max_decimal = (2**127 - 1) / decimal_divisor
+@pytest.mark.parametrize("val", [min_decimal, 0, max_decimal])
+def test_unary_sub_decimal_pass(get_contract, val):
+    code = """@public
+def negate(a: decimal) -> decimal:
+    return -(a)
+    """
+    c = get_contract(code)
+    assert c.negate(val) == -val
Repository: vyperlang/vyper

Issue:
Circumventing `@constant` with multiple return values and tuple assignment
Modifying state is not allowed in `@constant` functions, but you can bypass the check by using multiple return values:

```python
x: public(uint256)

@private
@constant
def returnTwo() -> (uint256, uint256):
    return 1, 2

@public
@constant
def foo():
    a: uint256 = 0
    a, self.x = self.returnTwo() # BUG
```


Discussion:
Meeting Notes: fix it.

Resolving patch:
diff --git a/vyper/parser/stmt.py b/vyper/parser/stmt.py
--- a/vyper/parser/stmt.py
+++ b/vyper/parser/stmt.py
@@ -987,18 +987,13 @@ def get_target(self, target):
                 self.stmt,
             )
         if isinstance(target, ast.Tuple):
-            return Expr(target, self.context).lll_node
+            target = Expr(target, self.context).lll_node
+            for node in target.args:
+                constancy_checks(node, self.context, self.stmt)
+            return target
+
         target = Expr.parse_variable_location(target, self.context)
-        if target.location == 'storage' and self.context.is_constant():
-            raise ConstancyViolationException(
-                f"Cannot modify storage inside {self.context.pp_constancy()}: {target.annotation}",
-                self.stmt,
-            )
-        if not target.mutable:
-            raise ConstancyViolationException(
-                f"Cannot modify function argument: {target.annotation}",
-                self.stmt,
-            )
+        constancy_checks(target, self.context, self.stmt)
         return target
 
     def parse_docblock(self):
@@ -1023,3 +1018,16 @@ def parse_body(code, context):
         o.append(lll)
     o.append('pass')  # force zerovalent, even last statement
     return LLLnode.from_list(o, pos=getpos(code[0]) if code else None)
+
+
+def constancy_checks(node, context, stmt):
+    if node.location == 'storage' and context.is_constant():
+        raise ConstancyViolationException(
+            f"Cannot modify storage inside {context.pp_constancy()}: {node.annotation}",
+            stmt,
+        )
+    if not node.mutable:
+        raise ConstancyViolationException(
+            f"Cannot modify function argument: {node.annotation}",
+            stmt,
+        )


Test patch:
diff --git a/tests/parser/syntax/test_tuple_assign.py b/tests/parser/syntax/test_tuple_assign.py
--- a/tests/parser/syntax/test_tuple_assign.py
+++ b/tests/parser/syntax/test_tuple_assign.py
@@ -84,7 +84,21 @@ def test(a: bytes32) -> (bytes32, uint256, int128):
     a, b, c = self._test(a)
     assert d == 123
     return a, b, c
-    """, ConstancyViolationException)
+    """, ConstancyViolationException),
+    ("""
+x: public(uint256)
+
+@private
+@constant
+def return_two() -> (uint256, uint256):
+    return 1, 2
+
+@public
+@constant
+def foo():
+    a: uint256 = 0
+    a, self.x = self.return_two()
+     """, ConstancyViolationException),
 ]
Repository: vyperlang/vyper

Issue:
Inappropriate overflow check for `addmod` and `mulmod`
`addmod` and `mulmod` should allow arbitrary `uint256` operands, but the following code performs a check for addition or multiplication overflow:

https://github.com/ethereum/vyper/blob/c296b2d7532d913103aad494b749f8179a3acddc/vyper/functions/functions.py#L1023-L1052

This results to the following runtime errors:

```python
@public
@constant
def test1(a: uint256, b: uint256) -> uint256:
    return uint256_addmod(a, b, 12) # test(2**255, 2**255) reverts
    
@public
@constant
def test2(a: uint256, b: uint256) -> uint256:
    return uint256_mulmod(a, b, 12) # test(2**255, 2) reverts
```


Discussion:
Remove the checks. The opcode's already perform modulo, so overflow/underflow isn't possible

Resolving patch:
diff --git a/vyper/functions/functions.py b/vyper/functions/functions.py
--- a/vyper/functions/functions.py
+++ b/vyper/functions/functions.py
@@ -1036,7 +1036,6 @@ def uint256_addmod(expr, args, kwargs, context):
         [
             'seq',
             ['assert', args[2]],
-            ['assert', ['or', ['iszero', args[1]], ['gt', ['add', args[0], args[1]], args[0]]]],
             ['addmod', args[0], args[1], args[2]],
         ],
         typ=BaseType('uint256'),
@@ -1050,11 +1049,6 @@ def uint256_mulmod(expr, args, kwargs, context):
         [
             'seq',
             ['assert', args[2]],
-            ['assert', [
-                'or',
-                ['iszero', args[0]],
-                ['eq', ['div', ['mul', args[0], args[1]], args[0]], args[1]],
-            ]],
             ['mulmod', args[0], args[1], args[2]],
         ],
         typ=BaseType('uint256'),


Test patch:
diff --git a/tests/parser/types/numbers/test_uint256.py b/tests/parser/types/numbers/test_uint256.py
--- a/tests/parser/types/numbers/test_uint256.py
+++ b/tests/parser/types/numbers/test_uint256.py
@@ -93,12 +93,12 @@ def _uint256_mulmod(x: uint256, y: uint256, z: uint256) -> uint256:
     assert c._uint256_addmod(1, 2, 2) == 1
     assert c._uint256_addmod(32, 2, 32) == 2
     assert c._uint256_addmod((2**256) - 1, 0, 2) == 1
-    assert_tx_failed(lambda: c._uint256_addmod((2**256) - 1, 1, 1))
+    assert c._uint256_addmod(2**255, 2**255, 6) == 4
     assert_tx_failed(lambda: c._uint256_addmod(1, 2, 0))
     assert c._uint256_mulmod(3, 1, 2) == 1
     assert c._uint256_mulmod(200, 3, 601) == 600
     assert c._uint256_mulmod(2**255, 1, 3) == 2
-    assert_tx_failed(lambda: c._uint256_mulmod(2**255, 2, 1))
+    assert c._uint256_mulmod(2**255, 2, 6) == 4
     assert_tx_failed(lambda: c._uint256_mulmod(2, 2, 0))
Repository: vyperlang/vyper

Issue:
Possible simplification for list return type checking
It seems that the following check:

https://github.com/ethereum/vyper/blob/c296b2d7532d913103aad494b749f8179a3acddc/vyper/parser/stmt.py#L869-L877

can simply be:

```python
if sub.typ.subtype != self.context.return_type.subtype:
    raise TypeMismatchException(
        f"List return type {sub.typ.subtype} does not match specified "
        f"return type, expecting {self.context.return_type.subtype}",
        self.stmt
    )
```


Discussion:

Resolving patch:
diff --git a/vyper/parser/stmt.py b/vyper/parser/stmt.py
--- a/vyper/parser/stmt.py
+++ b/vyper/parser/stmt.py
@@ -1,5 +1,3 @@
-import re
-
 from vyper import ast
 from vyper.ast_utils import (
     ast_to_dict,
@@ -877,13 +875,11 @@ def parse_return(self):
                 raise Exception(f"Invalid location: {sub.location}")
 
         elif isinstance(sub.typ, ListType):
-            sub_base_type = re.split(r'\(|\[', str(sub.typ.subtype))[0]
-            ret_base_type = re.split(r'\(|\[', str(self.context.return_type.subtype))[0]
             loop_memory_position = self.context.new_placeholder(typ=BaseType('uint256'))
-            if sub_base_type != ret_base_type:
+            if sub.typ != self.context.return_type:
                 raise TypeMismatchException(
-                    f"List return type {sub_base_type} does not match specified "
-                    f"return type, expecting {ret_base_type}",
+                    f"List return type {sub.typ} does not match specified "
+                    f"return type, expecting {self.context.return_type}",
                     self.stmt
                 )
             elif sub.location == "memory" and sub.value != "multi":


Test patch:
Repository: vyperlang/vyper

Issue:
Private functions can't have duplicate function selectors
This is an unnecessary constraint. Label names can be made unique.

```python
@private
@constant
def gfah(): pass

@private
@constant
def eexo(): pass

# error: Label with name priv_236395036 already exists!
```


Discussion:

Resolving patch:
diff --git a/vyper/signatures/interface.py b/vyper/signatures/interface.py
--- a/vyper/signatures/interface.py
+++ b/vyper/signatures/interface.py
@@ -275,11 +275,10 @@ def find_signature_conflicts(sigs: Sequence[FunctionSignature]) -> Conflicts:
 
 
 def check_valid_contract_interface(global_ctx, contract_sigs):
-    public_func_sigs = [
-        sig for sig in contract_sigs.values()
-        if isinstance(sig, FunctionSignature) and not sig.private
-    ]
-    func_conflicts = find_signature_conflicts(public_func_sigs)
+    # the check for private function collisions is made to prevent future
+    # breaking changes if we switch to internal calls (@iamdefinitelyahuman)
+    func_sigs = [sig for sig in contract_sigs.values() if isinstance(sig, FunctionSignature)]
+    func_conflicts = find_signature_conflicts(func_sigs)
 
     if len(func_conflicts) > 0:
         sig_1, sig_2 = func_conflicts[0]


Test patch:
diff --git a/tests/signatures/test_method_id_conflicts.py b/tests/signatures/test_method_id_conflicts.py
--- a/tests/signatures/test_method_id_conflicts.py
+++ b/tests/signatures/test_method_id_conflicts.py
@@ -51,6 +51,26 @@ def tgeo():
 def OwnerTransferV7b711143(a: uint256):
     pass
     """,
+    """
+# check collision between private method IDs
+@private
+@constant
+def gfah(): pass
+
+@private
+@constant
+def eexo(): pass
+    """,
+    """
+# check collision between private and public IDs
+@private
+@constant
+def gfah(): pass
+
+@public
+@constant
+def eexo(): pass
+    """
 ]
Repository: vyperlang/vyper

Issue:
`AttributeError: 'Attribute' object has no attribute 'id'` on constants
### Version Information

* vyper Version (output of `vyper --version`): 0.1.0b14+commit.4ac5ef5
 OS: osx
* Python Version (output of `python --version`): 3.7.5
* Environment (output of `pip freeze`): same as previous TSTL issues

### What's your issue about?

Compiling:

```
cv0: constant(address) = block.coinbase.balance
```

produces:

```
Error compiling: vfile.67808.vy
AttributeError: 'Attribute' object has no attribute 'id'
```




Discussion:
(this is new on latest git pull; confirm some other issues fixed, my regressions mostly down to that CompilerPanic on ranges)
I know this is just a bad error message, at heart, but I don't want to filter out `AttributeErrors` from the testing so a fix eventually would be good to aid fuzzing.
And "you can't make a constant from a call" would obviously be more user-friendly.
Great find! Hopefully, the fact that we haven't had an issue from you in a while means we're doing better 🤣

Resolving patch:
diff --git a/vyper/parser/expr.py b/vyper/parser/expr.py
--- a/vyper/parser/expr.py
+++ b/vyper/parser/expr.py
@@ -292,21 +292,22 @@ def variables(self):
     def attribute(self):
         # x.balance: balance of address x
         if self.expr.attr == 'balance':
-            if self.expr.value.id == "self" and version_check(begin="istanbul"):
-                return LLLnode.from_list(
-                    ['selfbalance'],
-                    typ=BaseType('uint256', {'wei': 1}),
-                    location=None,
-                    pos=getpos(self.expr),
-                )
             addr = Expr.parse_value_expr(self.expr.value, self.context)
             if not is_base_type(addr.typ, 'address'):
                 raise TypeMismatchException(
                     "Type mismatch: balance keyword expects an address as input",
                     self.expr
                 )
+            if (
+                isinstance(self.expr.value, ast.Name) and
+                self.expr.value.id == "self" and
+                version_check(begin="istanbul")
+            ):
+                seq = ['selfbalance']
+            else:
+                seq = ['balance', addr]
             return LLLnode.from_list(
-                ['balance', addr],
+                seq,
                 typ=BaseType('uint256', {'wei': 1}),
                 location=None,
                 pos=getpos(self.expr),


Test patch: