diff --git a/.gitattributes b/.gitattributes
index 73ba5fa736..cff1a24600 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -13180,6 +13180,7 @@ tests/webtbf/tw2751.pp svneol=native#text/plain
 tests/webtbf/tw2752.pp svneol=native#text/plain
 tests/webtbf/tw2787.pp svneol=native#text/plain
 tests/webtbf/tw2795.pp svneol=native#text/plain
+tests/webtbf/tw28338.pp svneol=native#text/plain
 tests/webtbf/tw2853.pp svneol=native#text/plain
 tests/webtbf/tw2853a.pp svneol=native#text/plain
 tests/webtbf/tw2853b.pp svneol=native#text/plain
diff --git a/compiler/ncal.pas b/compiler/ncal.pas
index 8a6372d918..089b9f9dd0 100644
--- a/compiler/ncal.pas
+++ b/compiler/ncal.pas
@@ -84,6 +84,7 @@ interface
           procedure register_created_object_types;
           function get_expect_loc: tcgloc;
        protected
+          function safe_call_self_node: tnode;
           procedure gen_vmt_entry_load; virtual;
           procedure gen_syscall_para(para: tcallparanode); virtual;
           procedure objc_convert_to_message_send;virtual;
@@ -2102,7 +2103,7 @@ implementation
         { inherited }
         else if (cnf_inherited in callnodeflags) then
           begin
-            selftree:=call_self_node.getcopy;
+            selftree:=safe_call_self_node.getcopy;
            { we can call an inherited class static/method from a regular method
              -> self node must change from instance pointer to vmt pointer)
            }
@@ -2158,7 +2159,7 @@ implementation
                           end;
                       end
                     else
-                      selftree:=call_self_node.getcopy
+                      selftree:=safe_call_self_node.getcopy
                   else
                     selftree:=methodpointer.getcopy;
                 end;
@@ -2195,7 +2196,7 @@ implementation
         else
           begin
             if methodpointer.nodetype=typen then
-              selftree:=call_self_node.getcopy
+              selftree:=safe_call_self_node.getcopy
             else
               selftree:=methodpointer.getcopy;
           end;
@@ -2333,6 +2334,17 @@ implementation
       end;
 
 
+    function tcallnode.safe_call_self_node: tnode;
+      begin
+        if not assigned(call_self_node) then
+          begin
+            CGMessage(parser_e_illegal_expression);
+            call_self_node:=cerrornode.create;
+          end;
+        result:=call_self_node;
+      end;
+
+
     procedure tcallnode.gen_vmt_entry_load;
       var
         vmt_def: trecorddef;
@@ -2468,7 +2480,7 @@ implementation
              temp:=ctempcreatenode.create(objcsupertype,objcsupertype.size,tt_persistent,false);
              addstatement(statements,temp);
              { initialize objc_super record }
-             selftree:=call_self_node.getcopy;
+             selftree:=safe_call_self_node.getcopy;
 
              { we can call an inherited class static/method from a regular method
                -> self node must change from instance pointer to vmt pointer)
diff --git a/tests/webtbf/tw28338.pp b/tests/webtbf/tw28338.pp
new file mode 100644
index 0000000000..86bab12fa0
--- /dev/null
+++ b/tests/webtbf/tw28338.pp
@@ -0,0 +1,17 @@
+{ %fail }
+
+{$mode objfpc}
+
+program Project1;
+type
+tmyobj=object
+            a:integer;
+            function getsize:integer;
+        end;
+function tmyobj.getsize:integer;
+begin
+     result:=sizeof(self);
+end;
+begin
+  writeln(tmyobj.getsize);
+end.