Skip to content

Commit

Permalink
fix #511
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuan committed Jun 3, 2024
1 parent 30bfd4a commit adf9b1b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CSharp.lua/CoreSystem.Lua/CoreSystem/Enum.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ local function hasFlag(this, flag)
if this == flag then
return true
end
return band(this, flag) ~= 0
return band(this, flag) == flag
end

Number.EnumToString = toString
Expand Down
20 changes: 20 additions & 0 deletions test/BridgeNetTests/Batch1/src/BasicCSharp/TestFromIssue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ public static void TestOf472()
Assert.AreEqual(Context.Instance, 2);
}

[Test]
public static void TestOf511() {
Assert.AreEqual(TestFlag.None.HasFlag(TestFlag.None), true);
Assert.AreEqual(TestFlag.None.HasFlag(TestFlag.A), false);
Assert.AreEqual(TestFlag.A.HasFlag(TestFlag.None), true);
Assert.AreEqual(TestFlag.A.HasFlag(TestFlag.A), true);
Assert.AreEqual(TestFlag.A.HasFlag(TestFlag.A | TestFlag.B), false);
Assert.AreEqual((TestFlag.A | TestFlag.B).HasFlag(TestFlag.A), true);
Assert.AreEqual((TestFlag.A | TestFlag.B).HasFlag(TestFlag.A | TestFlag.C), false);
}

private class BattleModelSlotPrototype {
public string a;
public string b;
Expand Down Expand Up @@ -221,4 +232,13 @@ static LuaContext()
Instance = 1;
}
}

[Flags]
public enum TestFlag
{
None = 0,
A = 1,
B = 2,
C = 4,
}
}

0 comments on commit adf9b1b

Please sign in to comment.