Skip to content

Commit

Permalink
Prepare UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-mikula-sonarsource committed Jun 28, 2024
1 parent 8f17ff9 commit 2818bfb
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,67 @@ public void UnknownFoo(object x)
var c = (UndefinedType)x; // Secondary
}
}

public void MultipleCasts_RootBlock(object arg)
{
_ = (Fruit)arg; // FN
_ = (Fruit)arg; // Sec-ondary
_ = (Fruit)arg; // Sec-ondary
}

public void MultipleCasts_SameBlock(object arg)
{
if (true)
{
_ = (Fruit)arg; // FN
_ = (Fruit)arg; // Sec-ondary
_ = (Fruit)arg; // Sec-ondary
}
}

public void MultipleCasts_NestedBlock(object arg)
{
_ = (Fruit)arg; // FN
if (true)
{
_ = (Fruit)arg; // Sec-ondary
foreach(var ch in "Lorem ipsum")
{
_ = (Fruit)arg; // Sec-ondary
_ = (Fruit)arg; // Sec-ondary
}
_ = (Fruit)arg; // Sec-ondary
}
}

public void MultipleCasts_Lambda(object arg)
{
_ = (Fruit)arg; // FN
Action a = () =>
{
_ = (Fruit)arg; // Sec-ondary
_ = (Fruit)arg; // Sec-ondary
};
Func<object, int> f = x =>
{
_ = (Fruit)arg; // Sec-ondary
_ = (Fruit)x;
return 0;
};
}

public void MultipleCastsDifferentBlocks(object arg)
{
if (true)
{
_ = (Fruit)arg; // Compliant, we only look into the current and nested blocks
}

while(false)
{
_ = (Fruit)arg;
}
}
}

public class Bar<T> { }
Expand Down

0 comments on commit 2818bfb

Please sign in to comment.