diff --git a/master_changes.md b/master_changes.md
index 82a86257d6d..4a03f1bb61a 100644
--- a/master_changes.md
+++ b/master_changes.md
@@ -39,6 +39,7 @@ users)
## Switch
* [BUG] Fix `opam switch remove
` failure when it is a linked switch [#6276 @btjorge - fix #6275]
+ * [BUG] Correctly handle `pkg.version` pattern in `opam switch list-available` [#6186 @arozovyk - fix #6152]
## Config
diff --git a/src/client/opamCommands.ml b/src/client/opamCommands.ml
index 1d1266926fe..91f69a3542b 100644
--- a/src/client/opamCommands.ml
+++ b/src/client/opamCommands.ml
@@ -2895,16 +2895,10 @@ let switch cli =
(OpamStd.List.concat_map ", " OpamRepositoryName.to_string
(OpamStd.Option.default (OpamGlobalState.repos_list gt) repos));
let filters =
- List.map (fun patt ->
- OpamListCommand.Pattern
- ({ OpamListCommand.default_pattern_selector with
- OpamListCommand.fields = ["name"; "version"] },
- patt))
- pattlist
+ OpamListCommand.pattern_selector ~concat:OpamFormula.ands pattlist
in
let all_compilers =
- OpamListCommand.filter ~base:compilers st
- (OpamFormula.ands (List.map (fun f -> OpamFormula.Atom f) filters))
+ OpamListCommand.filter ~base:compilers st filters
in
let compilers =
if all then
diff --git a/tests/reftests/switch-list-available.test b/tests/reftests/switch-list-available.test
index 0033974d6ed..46e4492fa5b 100644
--- a/tests/reftests/switch-list-available.test
+++ b/tests/reftests/switch-list-available.test
@@ -99,16 +99,20 @@ comp-b 3
comp-b 4
### opam switch list-available comp-b.1
# Listing available compilers from repositories: default
-# No matches found
+# Name # Version # Synopsis
+comp-b 1
### opam switch list-available comp-b.1 --all
# Listing available compilers from repositories: default
-# No matches found
+# Name # Version # Synopsis
+comp-b 1
### opam switch list-available comp-b.2
# Listing available compilers from repositories: default
# No matches found
+[NOTE] Some compilers have been hidden (e.g. pre-releases). If you want to display them, run: 'opam switch list-available --all'
### opam switch list-available comp-b.2 --all
# Listing available compilers from repositories: default
-# No matches found
+# Name # Version # Synopsis
+comp-b 2
###
opam-version: "2.0"
flags: compiler