nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: rsteube/carapace
Pull request #305 (2021-05-24 18:34:17)

zsh: mimic standard completion style
Mimic standard completion style by only showing one per line with an alligned `--` delimiter
related #rsteube/carapace-bin#417


Patch:
diff --git a/internal/zsh/action.go b/internal/zsh/action.go
index fb9f0ba..900c94c 100644
--- a/internal/zsh/action.go
+++ b/internal/zsh/action.go
@@ -18,9 +18,13 @@ var sanitizer = strings.NewReplacer(
 func ActionRawValues(currentWord string, nospace bool, values ...common.RawValue) string {
 	filtered := make([]common.RawValue, 0)
 
+	maxLength := 0
 	for _, r := range values {
 		if strings.HasPrefix(r.Value, currentWord) {
 			filtered = append(filtered, r)
+			if length := len(r.Display); length > maxLength {
+				maxLength = length
+			}
 		}
 	}
 
@@ -36,7 +40,7 @@ func ActionRawValues(currentWord string, nospace bool, values ...common.RawValue
 		if strings.TrimSpace(val.Description) == "" {
 			vals[index] = fmt.Sprintf("%v\t%v", val.Value, val.Display)
 		} else {
-			vals[index] = fmt.Sprintf("%v\t%v (%v)", val.Value, val.Display, val.TrimmedDescription())
+			vals[index] = fmt.Sprintf("%v\t%v %v-- %v", val.Value, val.Display, strings.Repeat(" ", maxLength-len(val.Display)), val.TrimmedDescription())
 		}
 	}
 	return strings.Join(vals, "\n")
diff --git a/internal/zsh/snippet.go b/internal/zsh/snippet.go
index 707e6e5..9281a00 100644
--- a/internal/zsh/snippet.go
+++ b/internal/zsh/snippet.go
@@ -35,7 +35,7 @@ function _%v_completion {
   # shellcheck disable=SC2034,2206
   vals=(${vals%%%%$'\001'*})
 
-  compadd -S "${suffix}" -d descriptions -a -- vals
+  compadd -l -S "${suffix}" -d descriptions -a -- vals
 }
 compquote '' 2>/dev/null && _%v_completion
 compdef _%v_completion %v


Test patch:
diff --git a/example/cmd/_test/zsh.sh b/example/cmd/_test/zsh.sh
index ab4b8ce..f5e495c 100644
--- a/example/cmd/_test/zsh.sh
+++ b/example/cmd/_test/zsh.sh
@@ -24,7 +24,7 @@ function _example_completion {
   # shellcheck disable=SC2034,2206
   vals=(${vals%%$'\001'*})
 
-  compadd -S "${suffix}" -d descriptions -a -- vals
+  compadd -l -S "${suffix}" -d descriptions -a -- vals
 }
 compquote '' 2>/dev/null && _example_completion
 compdef _example_completion example
Repository: rsteube/carapace
Pull request #337 (2021-09-24 06:47:15)

batch: added ToA()


Patch:
diff --git a/batch.go b/batch.go
index bb33280..6c85c22 100644
--- a/batch.go
+++ b/batch.go
@@ -26,6 +26,16 @@ func (b batch) Invoke(c Context) invokedBatch {
 	return invokedActions
 }
 
+// ToA converts the batch to a implicitly merged action which is a shortcut for:
+//   ActionCallback(func(c Context) Action {
+//	 	return batch.Invoke(c).Merge().ToA()
+//	 })
+func (b batch) ToA() Action {
+	return ActionCallback(func(c Context) Action {
+		return b.Invoke(c).Merge().ToA()
+	})
+}
+
 // Merge merges Actions of a batch
 func (b invokedBatch) Merge() InvokedAction {
 	switch len(b) {


Test patch:
diff --git a/batch_test.go b/batch_test.go
index 5fb187b..067f046 100644
--- a/batch_test.go
+++ b/batch_test.go
@@ -44,3 +44,18 @@ func TestBatchNone(t *testing.T) {
 	actual := b.Invoke(Context{}).Merge()
 	assertEqual(t, expected, actual)
 }
+
+func TestBatchToA(t *testing.T) {
+	b := Batch(
+		ActionValues("A", "B"),
+		ActionValues("B", "C"),
+		ActionValues("C", "D"),
+	)
+	expected := InvokedAction{
+		rawValues: common.RawValuesFrom("A", "B", "C", "D"),
+		nospace:   false,
+		skipcache: false,
+	}
+	actual := b.ToA().Invoke(Context{})
+	assertEqual(t, expected, actual)
+}
Repository: rsteube/carapace
Pull request #377 (2021-12-11 11:07:07)

elvish: fix deprecation notices from 0.17
related: https://github.com/rsteube/carapace-bin/pull/798



Patch:
diff --git a/internal/elvish/snippet.go b/internal/elvish/snippet.go
index c647493..7bcf3dd 100644
--- a/internal/elvish/snippet.go
+++ b/internal/elvish/snippet.go
@@ -8,8 +8,8 @@ import (
 
 // Snippet creates the elvish completion script
 func Snippet(cmd *cobra.Command) string {
-	return fmt.Sprintf(`edit:completion:arg-completer[%v] = [@arg]{
-    %v _carapace elvish _ (all $arg) | from-json | all (one) | each [c]{ edit:complex-candidate $c[Value] &display=$c[Display] &code-suffix=$c[CodeSuffix] }
+	return fmt.Sprintf(`set edit:completion:arg-completer[%v] = {|@arg|
+    %v _carapace elvish _ (all $arg) | from-json | all (one) | each {|c| edit:complex-candidate $c[Value] &display=$c[Display] &code-suffix=$c[CodeSuffix] }
 }
 `, cmd.Name(), uid.Executable())
 }


Test patch:
diff --git a/example/cmd/_test/elvish.elv b/example/cmd/_test/elvish.elv
index 2ca903b..4d527f0 100644
--- a/example/cmd/_test/elvish.elv
+++ b/example/cmd/_test/elvish.elv
@@ -1,4 +1,4 @@
-edit:completion:arg-completer[example] = [@arg]{
-    example _carapace elvish _ (all $arg) | from-json | all (one) | each [c]{ edit:complex-candidate $c[Value] &display=$c[Display] &code-suffix=$c[CodeSuffix] }
+set edit:completion:arg-completer[example] = {|@arg|
+    example _carapace elvish _ (all $arg) | from-json | all (one) | each {|c| edit:complex-candidate $c[Value] &display=$c[Display] &code-suffix=$c[CodeSuffix] }
 }
Repository: rsteube/carapace
Pull request #411 (2022-02-01 09:28:59)

fix linter warnings


Patch:
diff --git a/action.go b/action.go
index aee6aa4..2a44c94 100644
--- a/action.go
+++ b/action.go
@@ -127,8 +127,8 @@ func (a Action) Chdir(dir string) Action {
 	})
 }
 
-// Supress suppresses specific error messages using regular expressions
-func (a Action) Supress(expr ...string) Action {
+// Suppress suppresses specific error messages using regular expressions
+func (a Action) Suppress(expr ...string) Action {
 	return ActionCallback(func(c Context) Action {
 		invoked := a.Invoke(c)
 		filter := false
diff --git a/carapace.go b/carapace.go
index 2b6b143..22ebd1e 100644
--- a/carapace.go
+++ b/carapace.go
@@ -153,11 +153,11 @@ func complete(cmd *cobra.Command, args []string) (string, error) {
 		}
 	} else {
 		if len(args) == 1 {
-			if s, err := Gen(cmd).Snippet(args[0]); err != nil {
+			s, err := Gen(cmd).Snippet(args[0])
+			if err != nil {
 				return "", err
-			} else {
-				return s, nil
 			}
+			return s, nil
 		} else {
 			shell := args[0]
 			id := args[1]
diff --git a/internal/tcsh/snippet.go b/internal/tcsh/snippet.go
index c17fa46..6fc2216 100644
--- a/internal/tcsh/snippet.go
+++ b/internal/tcsh/snippet.go
@@ -8,6 +8,7 @@ import (
 	"github.com/spf13/cobra"
 )
 
+// Snippet creates the tcsh completion script
 func Snippet(cmd *cobra.Command) string {
 	// TODO initial version - needs to handle open quotes
 	return fmt.Sprintf("complete \"%v\" 'p@*@`echo \"$COMMAND_LINE'\"''\"'\" | xargs %v _carapace tcsh _ `@@' ;", cmd.Name(), uid.Executable())
diff --git a/pkg/ps/ps.go b/pkg/ps/ps.go
index 9293acc..0d2c35a 100644
--- a/pkg/ps/ps.go
+++ b/pkg/ps/ps.go
@@ -8,6 +8,7 @@ import (
 	"github.com/mitchellh/go-ps"
 )
 
+// DetermineShell determines shell by parent process name
 func DetermineShell() string {
 	process, err := ps.FindProcess(os.Getpid())
 	if err != nil {


Test patch:
diff --git a/action_test.go b/action_test.go
index 11a802a..0686515 100644
--- a/action_test.go
+++ b/action_test.go
@@ -167,7 +167,7 @@ func TestActionMessage(t *testing.T) {
 func TestActionMessageSuppress(t *testing.T) {
 	assertEqual(t,
 		Batch(
-			ActionMessage("example message").Supress("example"),
+			ActionMessage("example message").Suppress("example"),
 			ActionValues("test"),
 		).ToA().Invoke(Context{}),
 		ActionValues("test").noSpace(true).skipCache(true).Invoke(Context{}),
Repository: rsteube/carapace
Pull request #434 (2022-02-21 11:53:09)

bash-ble: skip completion when auto-invoked


Patch:
diff --git a/internal/bash_ble/snippet.go b/internal/bash_ble/snippet.go
index 3571b1b..244936c 100644
--- a/internal/bash_ble/snippet.go
+++ b/internal/bash_ble/snippet.go
@@ -18,6 +18,8 @@ func Snippet(cmd *cobra.Command) string {
 	result := fmt.Sprintf(`
 _%v_completion_ble() {
   if [[ ${BLE_ATTACHED-} ]]; then
+    [[ :$comp_type: == *:auto:* ]] && return
+
     bleopt complete_menu_style=desc
 
     local compline="${COMP_LINE:0:${COMP_POINT}}"


Test patch:
diff --git a/example/cmd/_test/bash-ble.sh b/example/cmd/_test/bash-ble.sh
index 3e32497..62c1509 100644
--- a/example/cmd/_test/bash-ble.sh
+++ b/example/cmd/_test/bash-ble.sh
@@ -17,6 +17,8 @@ _example_completion() {
 
 _example_completion_ble() {
   if [[ ${BLE_ATTACHED-} ]]; then
+    [[ :$comp_type: == *:auto:* ]] && return
+
     bleopt complete_menu_style=desc
 
     local compline="${COMP_LINE:0:${COMP_POINT}}"
Repository: rsteube/carapace
Pull request #435 (2022-03-04 19:58:22)

bash-ble: prevent default
#431



Patch:
diff --git a/internal/bash_ble/snippet.go b/internal/bash_ble/snippet.go
index 244936c..f055a84 100644
--- a/internal/bash_ble/snippet.go
+++ b/internal/bash_ble/snippet.go
@@ -20,6 +20,7 @@ _%v_completion_ble() {
   if [[ ${BLE_ATTACHED-} ]]; then
     [[ :$comp_type: == *:auto:* ]] && return
 
+    compopt -o ble/no-default
     bleopt complete_menu_style=desc
 
     local compline="${COMP_LINE:0:${COMP_POINT}}"


Test patch:
diff --git a/example/cmd/_test/bash-ble.sh b/example/cmd/_test/bash-ble.sh
index 62c1509..0ee8a6a 100644
--- a/example/cmd/_test/bash-ble.sh
+++ b/example/cmd/_test/bash-ble.sh
@@ -19,6 +19,7 @@ _example_completion_ble() {
   if [[ ${BLE_ATTACHED-} ]]; then
     [[ :$comp_type: == *:auto:* ]] && return
 
+    compopt -o ble/no-default
     bleopt complete_menu_style=desc
 
     local compline="${COMP_LINE:0:${COMP_POINT}}"
Repository: rsteube/carapace
Pull request #480 (2022-04-07 10:14:27)

traverse: fix flag value matching subcommand


Patch:
diff --git a/internal/common/traverse.go b/internal/common/traverse.go
index 8b79001..ad6a0d0 100644
--- a/internal/common/traverse.go
+++ b/internal/common/traverse.go
@@ -6,6 +6,7 @@ import (
 	"strings"
 
 	"github.com/spf13/cobra"
+	"github.com/spf13/pflag"
 )
 
 // TraverseLenient traverses the command tree but filters errors regarding arguments currently being completed
@@ -33,7 +34,8 @@ func TraverseLenient(cmd *cobra.Command, args []string) (*cobra.Command, []strin
 	for _, name := range append(targetCmd.Aliases, targetCmd.Name()) {
 		if len(args) > 0 &&
 			name == args[len(args)-1] &&
-			len(targetCmd.Flags().Args()) == 0 {
+			len(targetCmd.Flags().Args()) == 0 &&
+			!anyFlagChanged(targetCmd) {
 			if targetCmd.HasParent() {
 				targetCmd = targetCmd.Parent() // when argument currently being completed is fully matching a subcommand it will be returned, so fix this to parent
 			}
@@ -42,6 +44,13 @@ func TraverseLenient(cmd *cobra.Command, args []string) (*cobra.Command, []strin
 	return targetCmd, targetCmd.Flags().Args(), filterError(args, err)
 }
 
+func anyFlagChanged(cmd *cobra.Command) (changed bool) {
+	cmd.LocalFlags().VisitAll(func(f *pflag.Flag) {
+		changed = changed || f.Changed
+	})
+	return
+}
+
 func filterError(args []string, err error) error {
 	if err == nil || len(args) == 0 {
 		return err


Test patch:
diff --git a/internal/common/traverse_test.go b/internal/common/traverse_test.go
index 075b65a..b5f835b 100644
--- a/internal/common/traverse_test.go
+++ b/internal/common/traverse_test.go
@@ -101,3 +101,29 @@ func TestDisabledFlagParsing(t *testing.T) {
 	_, args, _ := testTraverseLenient(t, "sub2", "--arg")
 	assert.Equal(t, args[0], "--arg") // TODO test whole slice
 }
+
+func TestFlagValueMatchesCmd(t *testing.T) {
+	cmd, args, _ := testTraverseLenient(t, "--string", testCmd.Name())
+	if cmd != testCmd {
+		t.Errorf("should be testCmd [was: '%v']", cmd)
+	}
+	if len(args) != 0 {
+		t.Errorf("args should be empty [was: '%v']", len(args))
+	}
+	if v := cmd.Flag("string").Value.String(); v != testCmd.Use {
+		t.Errorf("string flag should be set [expected: '%v', was: '%v']", testCmd.Name(), v)
+	}
+}
+
+func TestFlagValueMatchesSubCmd(t *testing.T) {
+	cmd, args, _ := testTraverseLenient(t, "sub", "--substring", testSubCmd.Name())
+	if cmd != testSubCmd {
+		t.Errorf("should be testSubCmd [was: '%v']", cmd.Name())
+	}
+	if len(args) != 0 {
+		t.Errorf("args should be empty [was: '%v']", len(args))
+	}
+	if v := testSubCmd.Flag("substring").Value.String(); v != testSubCmd.Use {
+		t.Errorf("string flag should be set [expected: '%v', was: '%v']", testSubCmd.Name(), v)
+	}
+}
Repository: rsteube/carapace
Pull request #481 (2022-04-07 14:42:54)

zsh: zstyle config


Patch:
diff --git a/internal/shell/export/action.go b/internal/shell/export/action.go
index 9446298..971e20a 100644
--- a/internal/shell/export/action.go
+++ b/internal/shell/export/action.go
@@ -3,6 +3,7 @@ package export
 import (
 	"encoding/json"
 	"runtime/debug"
+	"sort"
 
 	"github.com/rsteube/carapace/internal/common"
 )
@@ -14,6 +15,7 @@ type Export struct {
 }
 
 func ActionRawValues(currentWord string, nospace bool, values common.RawValues) string {
+	sort.Sort(common.ByValue(values))
 	m, _ := json.Marshal(Export{
 		Version:   version(),
 		Nospace:   nospace,
diff --git a/internal/shell/zsh/snippet.go b/internal/shell/zsh/snippet.go
index b9ce303..defe8e0 100644
--- a/internal/shell/zsh/snippet.go
+++ b/internal/shell/zsh/snippet.go
@@ -27,7 +27,7 @@ function _%v_completion {
   fi
 
   export ZLS_COLOURS="${lines[1]}"
-  # TODO for ${curcontext}: zstyle ':completion:*' list-colors "${lines[1]}"
+  #zstyle ":completion:${curcontext}:*" list-colors "${lines[1]}"
   
   # shellcheck disable=SC2034,2206
   lines=(${lines[@]:1})


Test patch:
diff --git a/example/cmd/_test/zsh.sh b/example/cmd/_test/zsh.sh
index 7dd2ce9..28775ce 100644
--- a/example/cmd/_test/zsh.sh
+++ b/example/cmd/_test/zsh.sh
@@ -15,7 +15,7 @@ function _example_completion {
   fi
 
   export ZLS_COLOURS="${lines[1]}"
-  # TODO for ${curcontext}: zstyle ':completion:*' list-colors "${lines[1]}"
+  #zstyle ":completion:${curcontext}:*" list-colors "${lines[1]}"
   
   # shellcheck disable=SC2034,2206
   lines=(${lines[@]:1})
Repository: openllb/hlb
Pull request #287 (2022-02-05 05:48:47)

Add ref validation for downloadDockerTarball


Patch:
diff --git a/codegen/builtin_fs.go b/codegen/builtin_fs.go
index be891c4..6f25ff4 100644
--- a/codegen/builtin_fs.go
+++ b/codegen/builtin_fs.go
@@ -1019,6 +1019,12 @@ func (dot DownloadDockerTarball) Call(ctx context.Context, cln *client.Client, r
 		return err
 	}
 
+	named, err := reference.ParseNormalizedNamed(ref)
+	if err != nil {
+		return errdefs.WithInvalidImageRef(err, Arg(ctx, 1), ref)
+	}
+	ref = reference.TagNameOnly(named).String()
+
 	err = os.MkdirAll(filepath.Dir(localPath), 0755)
 	if err != nil {
 		return err


Test patch:
diff --git a/codegen/codegen_test.go b/codegen/codegen_test.go
index 974eaf4..f5e10b9 100644
--- a/codegen/codegen_test.go
+++ b/codegen/codegen_test.go
@@ -1012,6 +1012,16 @@ func TestCodegenError(t *testing.T) {
 		`,
 			"<stdin>:3:9: unrecognized builtin `includePatterns`",
 		},
+		{
+			"invalid downloadDockerTarball ref",
+			[]string{"default"},
+			`
+			fs default() {
+				downloadDockerTarball "image.tar" "#"
+			}
+		`,
+			"<stdin>:3:39: failed to parse `#`: invalid reference format",
+		},
 	} {
 		tc := tc
 		t.Run(tc.name, func(t *testing.T) {
Repository: openllb/hlb
Pull request #304 (2022-02-17 19:23:04)

Simplify ast.Find and fix tests
- Simplifies and addresses some test issues


Patch:
diff --git a/parser/ast/walk.go b/parser/ast/walk.go
index 6c58905..6514137 100644
--- a/parser/ast/walk.go
+++ b/parser/ast/walk.go
@@ -392,27 +392,20 @@ func (f *finder) Visit(_ Introspector, n Node) Visitor {
 	if n == nil {
 		return nil
 	}
-	if f.column == 0 {
-		if (f.line >= n.Position().Line && f.line <= n.End().Line) &&
-			(f.match == nil || n.End().Column <= f.match.End().Column) {
-			if f.line == n.Position().Line && f.line == n.End().Line {
-				keep := true
-				if f.filter != nil {
-					keep = f.filter(n)
-				}
-				if keep {
-					f.match = n
-				}
-			}
+	if IsPositionWithinNode(n, f.line, f.column) {
+		if f.column == 0 && f.line != n.Position().Line {
 			return f
 		}
-	} else if IsPositionWithinNode(n, f.line, f.column) {
+
 		keep := true
 		if f.filter != nil {
 			keep = f.filter(n)
 		}
 		if keep {
 			f.match = n
+			if f.column == 0 {
+				return nil
+			}
 		}
 		return f
 	}


Test patch:
diff --git a/parser/ast/walk_test.go b/parser/ast/walk_test.go
index b5f2faa..6e1a9ea 100644
--- a/parser/ast/walk_test.go
+++ b/parser/ast/walk_test.go
@@ -94,7 +94,19 @@ func TestFind(t *testing.T) {
 		`,
 		2, 0,
 		nil,
-		"2:2", "2:7", // image "alpine"
+		"2:2", "3:1", // image "alpine"
+	}, {
+		"no column match multiline",
+		`
+		fs default() {
+			image "alpine" with option {
+				resolve
+			}
+		}
+		`,
+		2, 0,
+		nil,
+		"2:2", "5:1", // image "alpine" with option { ... }
 	}, {
 		"column match node",
 		`
@@ -104,7 +116,7 @@ func TestFind(t *testing.T) {
 		`,
 		2, 3,
 		nil,
-		"2:2", "2:7", // image "alpine"
+		"2:2", "2:7", // image
 	}, {
 		"column match parent",
 		`
Repository: openllb/hlb
Pull request #99 (2020-04-16 03:47:33)

Add localEnv string builtin
See test for example.

I chose `localEnv` to distinguish it from the `env` instruction for `fs`. Perhaps `getEnv` is better? WDYT?


Patch:
diff --git a/builtin/builtin.go b/builtin/builtin.go
index f342151..74f3c4d 100644
--- a/builtin/builtin.go
+++ b/builtin/builtin.go
@@ -424,6 +424,11 @@ var (
 							parser.NewField(parser.Str, "values", true),
 						},
 					},
+					"localEnv": FuncLookup{
+						Params: []*parser.Field{
+							parser.NewField(parser.Str, "key", false),
+						},
+					},
 				},
 			},
 		},
diff --git a/codegen/codegen.go b/codegen/codegen.go
index 4bd0f8f..0d95ad3 100644
--- a/codegen/codegen.go
+++ b/codegen/codegen.go
@@ -414,6 +414,15 @@ func (cg *CodeGen) EmitStringChainStmt(ctx context.Context, scope *parser.Scope,
 		return func(_ string) (string, error) {
 			return fmt.Sprintf(formatStr, as...), nil
 		}, nil
+	case "localEnv":
+		key, err := cg.EmitStringExpr(ctx, scope, call, args[0])
+		if err != nil {
+			return nil, err
+		}
+
+		return func(_ string) (string, error) {
+			return os.Getenv(key), nil
+		}, nil
 	default:
 		// Must be a named reference.
 		obj := scope.Lookup(name)
diff --git a/language/builtin.hlb b/language/builtin.hlb
index 5bcf785..2bccb73 100644
--- a/language/builtin.hlb
+++ b/language/builtin.hlb
@@ -494,6 +494,12 @@ fs downloadDockerTarball(string localPath, string ref)
 # @return the resulting string from formatting.
 string format(string formatString, variadic string values)
 
+# An environment variable from the client's local environment.
+#
+# @param the environment variable's key.
+# @return the environment variable's value
+string localEnv(string key)
+
 # Execute groups in parallel.
 #
 # @param groups the groups to run in parallel


Test patch:
diff --git a/codegen/codegen_test.go b/codegen/codegen_test.go
index 36bb905..8e4f576 100644
--- a/codegen/codegen_test.go
+++ b/codegen/codegen_test.go
@@ -2,6 +2,7 @@ package codegen
 
 import (
 	"context"
+	"os"
 	"strings"
 	"testing"
 
@@ -77,6 +78,22 @@ func TestCodeGen(t *testing.T) {
 
 			return Expect(t, llb.Local(id, llb.SessionID(cg.SessionID())))
 		},
+	}, {
+		"local env",
+		[]string{"default"},
+		`
+		fs default() {
+			scratch
+			mkfile "home" 0o644 foo
+		}
+
+		string foo() {
+			localEnv "HOME"
+		}
+		`,
+		func(t *testing.T, cg *CodeGen) solver.Request {
+			return Expect(t, llb.Scratch().File(llb.Mkfile("home", 0644, []byte(os.Getenv("HOME")))))
+		},
 	}, {
 		"empty group",
 		[]string{"default"},
Repository: openllb/hlb
Pull request #116 (2020-04-22 02:28:46)

Emit error when calling module without selector
- Currently it panics, so this adds the appropriate checker error and tests.


Patch:
diff --git a/checker/checker.go b/checker/checker.go
index e45b1cf..9c7e15c 100644
--- a/checker/checker.go
+++ b/checker/checker.go
@@ -335,6 +335,9 @@ func (c *checker) checkBlockStmt(scope *parser.Scope, typ parser.ObjType, block
 					callType = n.Type
 				case *parser.AliasDecl:
 					callType = n.Func.Type
+				case *parser.ImportDecl:
+					c.errs = append(c.errs, ErrUseModuleWithoutSelector{Ident: call.Func.Ident})
+					continue
 				}
 			case parser.FieldKind:
 				field, ok := obj.Node.(*parser.Field)
diff --git a/checker/errors.go b/checker/errors.go
index 7b3838f..a010487 100644
--- a/checker/errors.go
+++ b/checker/errors.go
@@ -133,3 +133,11 @@ type ErrBadParse struct {
 func (e ErrBadParse) Error() string {
 	return fmt.Sprintf("%s unable to parse", FormatPos(e.Node.Position()))
 }
+
+type ErrUseModuleWithoutSelector struct {
+	Ident *parser.Ident
+}
+
+func (e ErrUseModuleWithoutSelector) Error() string {
+	return fmt.Sprintf("%s use of module %s without selector", FormatPos(e.Ident.Position()), e.Ident)
+}


Test patch:
diff --git a/checker/checker_test.go b/checker/checker_test.go
index 8952382..025b105 100644
--- a/checker/checker_test.go
+++ b/checker/checker_test.go
@@ -244,6 +244,25 @@ func TestChecker_Check(t *testing.T) {
 				Name: "duplicateAliasName",
 			}},
 		},
+	}, {
+		"errors when calling import",
+		`
+		import myImportedModule "./myModule.hlb"
+	
+		fs default() {
+			myImportedModule
+		}
+		`,
+		ErrUseModuleWithoutSelector{
+			Ident: &parser.Ident{
+				Pos: lexer.Position{
+					Filename: "<stdin>",
+					Line:     4,
+					Column:   1,
+				},
+				Name: "myImportedModule",
+			},
+		},
 	}, {
 		"basic function export",
 		`
Repository: openllb/hlb
Pull request #122 (2020-04-24 05:58:04)

Fix calling selector with arg from function field
- Fails with the new test without the fix, passes with the fix.


Patch:
diff --git a/checker/checker.go b/checker/checker.go
index 620812c..2089eef 100644
--- a/checker/checker.go
+++ b/checker/checker.go
@@ -200,7 +200,7 @@ func (c *checker) CheckSelectors(mod *parser.Module) error {
 			obj := mod.Scope.Lookup(n.Name())
 			if obj.Kind == parser.DeclKind {
 				if _, ok := obj.Node.(*parser.ImportDecl); ok {
-					scope := obj.Data.(*parser.Scope)
+					importScope := obj.Data.(*parser.Scope)
 
 					typ := fun.Type.ObjType
 					if typ == parser.Option {
@@ -210,15 +210,15 @@ func (c *checker) CheckSelectors(mod *parser.Module) error {
 
 					// Check call signature against the imported module's scope since it was
 					// declared there.
-					params, err := c.checkCallSignature(scope, typ, n, args)
+					params, err := c.checkCallSignature(importScope, typ, n, args)
 					if err != nil {
 						c.errs = append(c.errs, err)
 						return false
 					}
 
-					// Arguments are passed by value, so invoke the arguments in the main
-					// module's scope, not the imported module's scope.
-					err = c.checkCallArgs(mod.Scope, n, args, with, params)
+					// Arguments are passed by value, so invoke the arguments in the
+					// function's scope, not the imported module's scope.
+					err = c.checkCallArgs(fun.Scope, n, args, with, params)
 					if err != nil {
 						c.errs = append(c.errs, err)
 					}


Test patch:
diff --git a/checker/checker_test.go b/checker/checker_test.go
index 4e9d4ce..02d9c23 100644
--- a/checker/checker_test.go
+++ b/checker/checker_test.go
@@ -372,7 +372,7 @@ func TestChecker_CheckSelectors(t *testing.T) {
 		`
 		import myImportedModule "./myModule.hlb"
 	
-		fs badSelectorCaller() {
+		fs default() {
 			myImportedModule.validSelector
 		}
 		`,
@@ -382,7 +382,7 @@ func TestChecker_CheckSelectors(t *testing.T) {
 		`
 		import myImportedModule "./myModule.hlb"
 	
-		fs badSelectorCaller() {
+		fs default() {
 			myImportedModule.invalidSelector
 		}
 		`,
@@ -401,7 +401,7 @@ func TestChecker_CheckSelectors(t *testing.T) {
 		`
 		import myImportedModule "./myModule.hlb"
 	
-		fs badSelectorCaller() {
+		fs default() {
 			scratch
 			run "xyz" with option {
 				mount myImportedModule.validSelector "/mountpoint"
@@ -409,12 +409,24 @@ func TestChecker_CheckSelectors(t *testing.T) {
 		}
 		`,
 		nil,
+	}, {
+		"able to pass function field as argument to selector",
+		`
+		import myImportedModule "./myModule.hlb"
+	
+		fs default(string foo) {
+			myImportedModule.validSelectorWithArgs foo
+		}
+		`,
+		nil,
 	}} {
 		tc := tc
 		t.Run(tc.name, func(t *testing.T) {
 			importedModuleDefinition := `
 				export validSelector
+				export validSelectorWithArgs
 				fs validSelector() {}
+				fs validSelectorWithArgs(string bar) {}
 			`
 
 			importedModule, err := parser.Parse(strings.NewReader(importedModuleDefinition))