- Notifications
You must be signed in to change notification settings - Fork 1.1k
i22587 Divergence check for Match Types #24661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Lluc24 wants to merge 5 commits into scala:main Choose a base branch from Lluc24:i22587-divergence-check-MT
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+127 −10
Draft
Changes from all commits
Commits
Show all changes
5 commits Select commit Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Test Case 2: Direct Self-Reference Without Reduction (NEGATIVE) | ||
| // This SHOULD diverge because Loop[X] immediately expands to Loop[X] | ||
| // with no progress made - infinite loop without termination | ||
| | ||
| type Loop[X] = X match | ||
| case Int => Loop[Int] | ||
| case _ => String | ||
| | ||
| @main def test02(): Unit = | ||
| val e1: Loop[Int] = ??? // error | ||
| println("Test 2 - Direct self-reference:") | ||
| println(s"e1 value: $e1") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Test Case 3: Wrapping Type Without Progress (NEGATIVE) | ||
| // This SHOULD diverge because Wrap[Int] => Wrap[List[Int]] => Wrap[List[List[Int]]] => ... | ||
| // The type grows infinitely without reaching a base case | ||
| | ||
| type Wrap[X] = X match | ||
| case AnyVal => Wrap[List[Int]] | ||
| | ||
| @main def test03(): Unit = | ||
| val e1: Wrap[Int] = ??? // error | ||
| println("Test 3 - Wrapping without progress:") | ||
| println(s"e1 value: $e1") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Test Case 5: Two-Parameter Match Type with Swapping (Negative) | ||
| // This should diverge because even though recursion should reduce, | ||
| // the sum of parameters size does not decrease in one recursive step. | ||
| | ||
| type Swap[X, Y] = (X, Y) match | ||
| case (Int, String) => Swap[Y, X] | ||
| case (String, Int) => X | ||
| case (List[a], b) => Swap[a, b] | ||
| case (a, List[b]) => Swap[a, b] | ||
| case _ => X | ||
| | ||
| @main def test05(): Unit = | ||
| val e: Swap[List[List[Int]], List[String]] = ??? // error | ||
| println(s"e value: $e") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Test Case 1: Simple Recursive Deconstruction (POSITIVE) | ||
| // This should NOT diverge because recursion always reduces the type structure | ||
| // by unwrapping one layer (Option[t] -> t) | ||
| | ||
| type Unwrap[X] = X match | ||
| case Option[t] => Unwrap[t] | ||
| case _ => X | ||
| | ||
| @main def test01(): Unit = | ||
| val e1: Unwrap[Option[Option[Int]]] = 42 | ||
| println("Test 1 - Simple recursive unwrapping:") | ||
| println(s"e1 value: $e1") | ||
| | ||
| val e2: Unwrap[Option[String]] = "hello" | ||
| println(s"e2 value: $e2") | ||
| | ||
| val e3: Unwrap[Int] = 99 | ||
| println(s"e3 value: $e3") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Test Case 4: Two-Parameter Match Type with Swapping (POSITIVE) | ||
| // This should NOT diverge because even though parameters swap positions, | ||
| // the tuple structure reduces (Tuple2 -> single type) | ||
| | ||
| type Swap[X, Y] = (X, Y) match | ||
| case (Int, String) => Y | ||
| case (String, Int) => X | ||
| case (List[a], b) => Swap[a, b] | ||
| case (a, List[b]) => Swap[a, b] | ||
| case _ => X | ||
| | ||
| @main def test04(): Unit = | ||
| val e1: Swap[Int, String] = "result" | ||
| println("Test 4 - Two-parameter swap:") | ||
| println(s"e1 value: $e1") | ||
| | ||
| val e2: Swap[String, Int] = "swapped" | ||
| println(s"e2 value: $e2") | ||
| | ||
| val e3: Swap[List[List[Int]], List[String]] = "42" | ||
| println(s"e3 value: $e3") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List[Int]is not AnyVal , so then it stops there right?