Skip to content

Commit

Permalink
[generator] Remove unreachable code (dotnet#8237)
Browse files Browse the repository at this point in the history
An earlier `wrap != null` condition ends with a `return` so any check or
code assuming `wrap == null` must always be executed, while any `wrap != null`
will never be.
  • Loading branch information
spouliot authored Mar 30, 2020
1 parent bdce026 commit 16ce9c6
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions src/generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4715,20 +4715,18 @@ void GenerateProperty (Type type, PropertyInfo pi, List<string> instance_fields_

string var_name = null;

if (wrap == null) {
// [Model] has properties that only throws, so there's no point in adding unused backing fields
if (!is_model && DoesPropertyNeedBackingField (pi) && !is_interface_impl && !minfo.is_static && !DoesPropertyNeedDirtyCheck (pi, export)) {
var_name = string.Format ("__mt_{0}_var{1}", pi.Name, minfo.is_static ? "_static" : "");
// [Model] has properties that only throws, so there's no point in adding unused backing fields
if (!is_model && DoesPropertyNeedBackingField (pi) && !is_interface_impl && !minfo.is_static && !DoesPropertyNeedDirtyCheck (pi, export)) {
var_name = string.Format ("__mt_{0}_var{1}", pi.Name, minfo.is_static ? "_static" : "");

print_generated_code ();
print_generated_code ();

if (minfo.is_thread_static)
print ("[ThreadStatic]");
print ("{1}object {0};", var_name, minfo.is_static ? "static " : "");
if (minfo.is_thread_static)
print ("[ThreadStatic]");
print ("{1}object {0};", var_name, minfo.is_static ? "static " : "");

if (!minfo.is_static && !is_interface_impl){
instance_fields_to_clear_on_dispose.Add (var_name);
}
if (!minfo.is_static && !is_interface_impl){
instance_fields_to_clear_on_dispose.Add (var_name);
}
}

Expand Down Expand Up @@ -4759,21 +4757,7 @@ void GenerateProperty (Type type, PropertyInfo pi, List<string> instance_fields_
use_underscore ? "_" : "");
indent++;

if (wrap != null) {
if (pi.CanRead) {
PrintPlatformAttributes (pi);
PrintPlatformAttributes (pi.GetGetMethod ());
print ("get {{ return {0} as {1}; }}", wrap, FormatType (pi.DeclaringType, GetCorrectGenericType (pi.PropertyType)));
}
if (pi.CanWrite) {
PrintPlatformAttributes (pi);
PrintPlatformAttributes (pi.GetSetMethod ());
print ("set {{ {0} = value; }}", wrap);
}
indent--;
print ("}\n");
return;
} else if (minfo.has_inner_wrap_attribute) {
if (minfo.has_inner_wrap_attribute) {
// If property getter or setter has its own WrapAttribute we let the user do whatever their heart desires
if (pi.CanRead) {
PrintAttributes (pi, platform: true);
Expand Down

0 comments on commit 16ce9c6

Please sign in to comment.