<NME> ElmPatternResolveTest.kt
<BEF> package org.elm.lang.core.resolve


/**
 * Tests related to pattern matching and destructuring
 */
class ElmPatternResolveTest: ElmResolveTestBase() {


    fun `test case-of pattern wildcard`() = checkByCode(
"""
f x =
    case x of
        0 -> 0
        0 -> 0
        y -> 2 * y
      --X      --^
"""


    fun `test case-of pattern union type constructor`() = checkByCode(
"""
f x =
    case x of
        Nothing -> 0
        Nothing -> 0
        Just something -> something
             --X          --^
    )


    fun `test function parameter record destructuring`() = checkByCode(
"""
foo { name } = name
      --X      --^
""")


    fun `test function parameter tuple destructuring`() = checkByCode(
"""
foo ( x, y ) = x + y
       --X       --^
""")


    fun `test top-level value destructuring`() = checkByCode(
"""
( x, y ) = (0, 0)
   --X

    fun `test function parameter tuple destructuring`() = checkByCode(
            """
foo ( x, y ) = x + y


    fun `test nested function parameter destructuring`() = checkByCode(
"""
f =
    let
        g ( x, y ) = x + y
    let
        g ( x, y ) = x + y
             --X       --^
""")


    fun `test pattern alias in function decl parameter`() = checkByCode(
"""
foo ((x, y) as point) = point
               --X      --^
""")


    fun `test pattern alias in let-in decl`() = checkByCode(
"""
f =
    let
        g ((x, y) as point) = point
    let
        g ((x, y) as point) = point
                     --X      --^
    in


    fun `test pattern alias in case-of branch`() = checkByCode(
"""
f x =
    case x of
        ((x, y) as point) -> point
    let
        ((x, y) as point) = (320, 480)
                   --X
    in
        point
        --^
""")


    fun `test pattern alias in case-of branch`() = checkByCode(
            """
f x =
    case x of
        ((x, y) as point) -> point
                   --X       --^
""")


}

<MSG> Fix ref resolve for case-of branches and anonymous functions (#108)

Both ElmCaseOfBranch and ElmAnonymousFunction were being 
too lenient when providing the names which it introduces into the 
lexical scope.

We were descending down into both the patterns on the left-side of
the branch (good) AND the expression on the right-hand side (bad!)
<DFF> @@ -4,11 +4,14 @@ package org.elm.lang.core.resolve
 /**
  * Tests related to pattern matching and destructuring
  */
-class ElmPatternResolveTest: ElmResolveTestBase() {
+class ElmPatternResolveTest : ElmResolveTestBase() {
+
+
+    // CASE-OF EXPRESSIONS AND PATTERNS
 
 
     fun `test case-of pattern wildcard`() = checkByCode(
-"""
+            """
 f x =
     case x of
         0 -> 0
@@ -19,7 +22,7 @@ f x =
 
 
     fun `test case-of pattern union type constructor`() = checkByCode(
-"""
+            """
 f x =
     case x of
         Nothing -> 0
@@ -29,22 +32,64 @@ f x =
     )
 
 
-    fun `test function parameter record destructuring`() = checkByCode(
+    fun `test case-of that should not resolve`() = checkByCode(
+            """
+f x =
+    case () of
+        Just foo -> ()
+        _ -> foo
+             --^unresolved
+"""
+    )
+
+
+    fun `test nested case-of`() = checkByCode(
+            """
+f x =
+    case () of
+        _ ->
+            case () of
+                _ -> ()
+                Just foo -> foo
+                     --X    --^
+"""
+    )
+
+
+    // see bug https://github.com/klazuka/intellij-elm/issues/106
+    fun `test nested case-of that should not resolve`() = checkByCode(
+            """
+f x =
+    case () of
+        _ ->
+            case () of
+                Just foo -> ()
+                _ -> foo
+                     --^unresolved
 """
+    )
+
+
+    // PARAMETER DESTRUCTURING
+
+
+    fun `test function parameter record destructuring`() = checkByCode(
+            """
 foo { name } = name
       --X      --^
 """)
 
 
     fun `test function parameter tuple destructuring`() = checkByCode(
-"""
+            """
 foo ( x, y ) = x + y
        --X       --^
 """)
 
 
+    // TODO [drop 0.18] this becomes invalid at the top-level in 0.19
     fun `test top-level value destructuring`() = checkByCode(
-"""
+            """
 ( x, y ) = (0, 0)
    --X
 
@@ -54,7 +99,7 @@ f = y + 20
 
 
     fun `test nested function parameter destructuring`() = checkByCode(
-"""
+            """
 f =
     let
         g ( x, y ) = x + y
@@ -64,15 +109,18 @@ f =
 """)
 
 
+    // PATTERN ALIASES
+
+
     fun `test pattern alias in function decl parameter`() = checkByCode(
-"""
+            """
 foo ((x, y) as point) = point
                --X      --^
 """)
 
 
     fun `test pattern alias in let-in decl`() = checkByCode(
-"""
+            """
 f =
     let
         g ((x, y) as point) = point
@@ -83,7 +131,7 @@ f =
 
 
     fun `test pattern alias in case-of branch`() = checkByCode(
-"""
+            """
 f x =
     case x of
         ((x, y) as point) -> point

Fix ref resolve for case-of branches and anonymous functions (#108)