Browse Source

Fix CS0162 warning about unreachable code (#1492)

pull/1495/head
josetr 5 years ago committed by GitHub
parent
commit
20dbda0405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 4
      src/Generator/Generators/CSharp/CSharpSourcesExtensions.cs
  3. 2
      src/Generator/Utils/BlockGenerator.cs

8
src/Generator/Generators/CSharp/CSharpSources.cs

@ -996,6 +996,8 @@ namespace CppSharp.Generators.CSharp @@ -996,6 +996,8 @@ namespace CppSharp.Generators.CSharp
WriteLine($@"throw new MissingMethodException(""Method {
property.Name} missing from explicit specialization {
@class.Visit(TypePrinter)}."");");
AddBlock(new Block(BlockKind.Unreachable));
return;
}
property = actualProperty;
@ -1325,6 +1327,8 @@ namespace CppSharp.Generators.CSharp @@ -1325,6 +1327,8 @@ namespace CppSharp.Generators.CSharp
WriteLine($@"throw new MissingMethodException(""Method {
property.Name} missing from explicit specialization {
@class.Visit(TypePrinter)}."");");
AddBlock(new Block(BlockKind.Unreachable));
return;
}
GenerateFunctionInProperty(@class, actualProperty.GetMethod, actualProperty,
@ -2633,6 +2637,8 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty @@ -2633,6 +2637,8 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
WriteLine($@"throw new MissingMethodException(""Method {
method.Name} missing from explicit specialization {
@class.Visit(TypePrinter)}."");");
AddBlock(new Block(BlockKind.Unreachable));
return;
}
if (specializedMethod.Ignore)
@ -2640,6 +2646,8 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty @@ -2640,6 +2646,8 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
WriteLine($@"throw new MissingMethodException(""Method {
method.Name} ignored in specialization {
@class.Visit(TypePrinter)}."");");
AddBlock(new Block(BlockKind.Unreachable));
return;
}

4
src/Generator/Generators/CSharp/CSharpSourcesExtensions.cs

@ -105,11 +105,13 @@ namespace CppSharp.Generators.CSharp @@ -105,11 +105,13 @@ namespace CppSharp.Generators.CSharp
foreach (var specialization in @class.Specializations.Where(s => s.IsGenerated))
{
WriteTemplateSpecializationCheck(gen, @class, specialization);
gen.PushBlock(BlockKind.Block);
gen.WriteOpenBraceAndIndent();
generate(specialization);
if (isVoid)
if (isVoid && !gen.ActiveBlock.FindBlocks(BlockKind.Unreachable).Any())
gen.WriteLine("return;");
gen.UnindentAndWriteCloseBrace();
gen.PopBlock();
}
ThrowException(gen, @class);
}

2
src/Generator/Utils/BlockGenerator.cs

@ -17,6 +17,7 @@ namespace CppSharp @@ -17,6 +17,7 @@ namespace CppSharp
public enum BlockKind
{
Unknown,
Block,
BlockComment,
InlineComment,
Header,
@ -36,6 +37,7 @@ namespace CppSharp @@ -36,6 +37,7 @@ namespace CppSharp
Event,
Variable,
Property,
Unreachable,
Field,
VTableDelegate,
Region,

Loading…
Cancel
Save