diff --git a/CHANGELOG.md b/CHANGELOG.md index f6410769c..2337afacf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,13 @@ # Changelog ## 1.5.6 -* Added: Support for new core Api `haxe.Rest` abstract type +* Added: Support for core Api `haxe.Rest` & `Single` abstract types +* Improvement: better support for switch capture variables (wip) * Bugfix: variable shadowing should now resolve to the correct declaration. * Bugfix: Incorrect caching of returnType for recursive methods * Bugfix: Allow uninitialized final fields in abstract enums * Bugfix: Allow assign from underlying type inside abstract enums +* Bugfix: Fixed issue with autocompletion in lime/openFL project xmls +* Bugfix: fixed incorrect handling of for/while loop array initializers * Changed: Renaming class will now also rename file/module if names are the same. ## 1.5.5 diff --git a/src/test/java/com/intellij/plugins/haxe/ide/HaxeSemanticAnnotatorTest.java b/src/test/java/com/intellij/plugins/haxe/ide/HaxeSemanticAnnotatorTest.java index f8e8a75cb..f221ee98b 100644 --- a/src/test/java/com/intellij/plugins/haxe/ide/HaxeSemanticAnnotatorTest.java +++ b/src/test/java/com/intellij/plugins/haxe/ide/HaxeSemanticAnnotatorTest.java @@ -854,7 +854,12 @@ public void testTypeParameterAnonymousStructure() throws Throwable { doTestNoFixWithWarnings(); } @Test - public void testSwitchEumVariableCapture() throws Throwable { + public void testSwitchPatternMatching() throws Throwable { + myFixture.enableInspections(HaxeUnresolvedSymbolInspection.class); + doTestNoFixWithWarnings(); + } + @Test + public void testSwitchStatements() throws Throwable { myFixture.enableInspections(HaxeUnresolvedSymbolInspection.class); doTestNoFixWithWarnings(); } diff --git a/src/test/resources/testData/annotation.semantic/SwitchEumVariableCapture.hx b/src/test/resources/testData/annotation.semantic/SwitchPatternMatching.hx similarity index 85% rename from src/test/resources/testData/annotation.semantic/SwitchEumVariableCapture.hx rename to src/test/resources/testData/annotation.semantic/SwitchPatternMatching.hx index 1981832e0..ca87b915a 100644 --- a/src/test/resources/testData/annotation.semantic/SwitchEumVariableCapture.hx +++ b/src/test/resources/testData/annotation.semantic/SwitchPatternMatching.hx @@ -15,6 +15,8 @@ class PatternMachingTest { var enumVal = Test.TAny(myArray); // correct switch(enumVal) { + //TODO mlo : needs resolver work + case TString(x = s): x.toLowerCase(); case TString(s): s.toLowerCase(); case TInt(i): i * 2; case TAny(a): a.indexOf(""); diff --git a/src/test/resources/testData/annotation.semantic/SwitchStatements.hx b/src/test/resources/testData/annotation.semantic/SwitchStatements.hx new file mode 100644 index 000000000..86d5c9f0c --- /dev/null +++ b/src/test/resources/testData/annotation.semantic/SwitchStatements.hx @@ -0,0 +1,89 @@ +package ; + +function add(a:Int, b:Int) return a + b; +function mul(a:Int, b:Int) return a * b; +function isEven(value:Float) return value % 2 == 0; + + +class PatternMachingTest { + public function testEumVariableCapture() { + var value = 1; + switch value { + // capture variable + case special = 1: + trace(special * 2); + + // multiple values + case 2 | 4 | 6: + trace("2 or 4 or 6 number"); + + // match expression + case _ * 2 => 10: + trace("found 5"); + + // match expresion with function call + case add(_, 1) => result: + trace(result > 1); + + //complex matching expressiom + case mul(add(_, 1), 3) => result: + trace(result > 1); + + //chained matching expressiom + case add(_, 1) => mul(_, 3) => result: + trace(result > 1); + + // matching expression with capture + //TODO mlo: needs work + case value = isEven(_) => true: + trace("even number: " + value); + + // match anything + case _: trace ("anything"); + + // capture variable + case var other: + trace("other: " + other); + } + } + + public function testSwitchOnArray() { + var myArray = [1, 6] ; + switch (myArray) { + case [2, _]: + trace("0"); + case [_, 6]: + trace("1"); + case []: + trace("2"); + case [_, _, _]: + trace("3"); + case _: + trace("4"); + } + } + + public function testSwitchOnStructure() { + var person = { name: "Mark", age: 33 }; + + switch person { + // match person with age older than 50 + case { age: _ > 50 => true}: + trace('found somebody older than 50'); + + // match on specific person named Jose who is 42 + case { name: "Jose", age: 42 }: + trace('Found Jose, who is 42'); + + // match on name + //TODO mlo: needs resolver work + case { name: name }: + trace('Found someone called $name'); + + // matches anything + case _: + trace("unknown"); + } + } + +} \ No newline at end of file