diff --git a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php
index <HASH>..<HASH> 100644
--- a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php
+++ b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php
@@ -691,6 +691,9 @@ class ExpressionAnalyzer
 
                     $context->hasVariable($var_id, $statements_analyzer);
                 }
+            } elseif ($var_id === '$this') {
+                // don't allow changing $this
+                return;
             } else {
                 $existing_type = $context->vars_in_scope[$var_id];
 
diff --git a/tests/ReferenceConstraintTest.php b/tests/ReferenceConstraintTest.php
index <HASH>..<HASH> 100644
--- a/tests/ReferenceConstraintTest.php
+++ b/tests/ReferenceConstraintTest.php
@@ -131,6 +131,18 @@ class ReferenceConstraintTest extends TestCase
                     '$b' => 'bool',
                 ],
             ],
+            'dontChangeThis' => [
+                '<?php
+                    interface I {}
+                    class C implements I {
+                        public function foo() : self {
+                            bar($this);
+                            return $this;
+                        }
+                    }
+
+                    function bar(I &$i) : void {}',
+            ],
         ];
     }
Don’t change value of $this by reference