Skip to content

Commit

Permalink
Static-check fixes from @lespea #1657, batch 5/n (#1707)
Browse files Browse the repository at this point in the history
* Static-check fixes from @lespea #1657, batch 2/n

* Static-check fixes from @lespea #1657, batch 3/n

* Static-check fixes from @lespea #1657, batch 4/n

* Static-check fixes from @lespea #1657, batch 5/n
  • Loading branch information
johnkerl authored Oct 27, 2024
1 parent 8c791f5 commit 02bd534
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
3 changes: 3 additions & 0 deletions pkg/dsl/cst/udf.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ func (root *RootNode) BuildUDF(
"function return value",
returnValueTypeName,
)
if err != nil {
return nil, err
}

lib.InternalCodingErrorIf(parameterListASTNode.Type != dsl.NodeTypeParameterList)
lib.InternalCodingErrorIf(parameterListASTNode.Children == nil)
Expand Down
1 change: 0 additions & 1 deletion pkg/input/pseudo_reader_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func (reader *PseudoReaderGen) process(

if recordsAndContexts.Len() > 0 {
readerChannel <- recordsAndContexts
recordsAndContexts = list.New()
}
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/lib/halfpipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (

func OpenOutboundHalfPipe(commandString string) (*os.File, error) {
readPipe, writePipe, err := os.Pipe()
if err != nil {
return nil, err
}

var procAttr os.ProcAttr
procAttr.Files = []*os.File{
Expand Down Expand Up @@ -56,6 +59,9 @@ func OpenOutboundHalfPipe(commandString string) (*os.File, error) {

func OpenInboundHalfPipe(commandString string) (*os.File, error) {
readPipe, writePipe, err := os.Pipe()
if err != nil {
return nil, err
}

var procAttr os.ProcAttr
procAttr.Files = []*os.File{
Expand Down
44 changes: 22 additions & 22 deletions pkg/mlrval/mlrval_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ import (

func TestGetString(t *testing.T) {
mv := FromInferredType("234")
stringval, ok := mv.GetStringValue()
_, ok := mv.GetStringValue()
assert.False(t, ok)

mv = FromDeferredType("234")
stringval, ok = mv.GetStringValue()
_, ok = mv.GetStringValue()
assert.False(t, ok)

mv = FromInferredType("234.5")
stringval, ok = mv.GetStringValue()
_, ok = mv.GetStringValue()
assert.False(t, ok)

mv = FromDeferredType("234.5")
stringval, ok = mv.GetStringValue()
_, ok = mv.GetStringValue()
assert.False(t, ok)

mv = FromInferredType("abc")
stringval, ok = mv.GetStringValue()
stringval, ok := mv.GetStringValue()
assert.Equal(t, "abc", stringval)
assert.True(t, ok)

Expand Down Expand Up @@ -60,33 +60,33 @@ func TestGetIntValue(t *testing.T) {
assert.True(t, ok)

mv = FromInferredType("123.4")
intval, ok = mv.GetIntValue()
_, ok = mv.GetIntValue()
assert.False(t, ok)

mv = FromDeferredType("123.4")
intval, ok = mv.GetIntValue()
_, ok = mv.GetIntValue()
assert.False(t, ok)

mv = FromInferredType("abc")
intval, ok = mv.GetIntValue()
_, ok = mv.GetIntValue()
assert.False(t, ok)

mv = FromDeferredType("abc")
intval, ok = mv.GetIntValue()
_, ok = mv.GetIntValue()
assert.False(t, ok)
}

func TestGetFloatValue(t *testing.T) {
mv := FromInferredType("234")
floatval, ok := mv.GetFloatValue()
_, ok := mv.GetFloatValue()
assert.False(t, ok)

mv = FromDeferredType("234")
floatval, ok = mv.GetFloatValue()
_, ok = mv.GetFloatValue()
assert.False(t, ok)

mv = FromInferredType("234.5")
floatval, ok = mv.GetFloatValue()
floatval, ok := mv.GetFloatValue()
assert.Equal(t, 234.5, floatval)
assert.True(t, ok)

Expand All @@ -96,11 +96,11 @@ func TestGetFloatValue(t *testing.T) {
assert.True(t, ok)

mv = FromInferredType("abc")
floatval, ok = mv.GetFloatValue()
_, ok = mv.GetFloatValue()
assert.False(t, ok)

mv = FromDeferredType("abc")
floatval, ok = mv.GetFloatValue()
_, ok = mv.GetFloatValue()
assert.False(t, ok)
}

Expand All @@ -126,38 +126,38 @@ func TestGetNumericToFloatValue(t *testing.T) {
assert.True(t, ok)

mv = FromInferredType("abc")
floatval, ok = mv.GetNumericToFloatValue()
_, ok = mv.GetNumericToFloatValue()
assert.False(t, ok)

mv = FromDeferredType("abc")
floatval, ok = mv.GetNumericToFloatValue()
_, ok = mv.GetNumericToFloatValue()
assert.False(t, ok)
}

func TestGetBoolValue(t *testing.T) {
mv := FromInferredType("234")
boolval, ok := mv.GetBoolValue()
_, ok := mv.GetBoolValue()
assert.False(t, ok)

mv = FromDeferredType("234")
boolval, ok = mv.GetBoolValue()
_, ok = mv.GetBoolValue()
assert.False(t, ok)

mv = FromInferredType("abc")
boolval, ok = mv.GetBoolValue()
_, ok = mv.GetBoolValue()
assert.False(t, ok)

mv = FromDeferredType("abc")
boolval, ok = mv.GetBoolValue()
_, ok = mv.GetBoolValue()
assert.False(t, ok)

mv = FromInferredType("true")
boolval, ok = mv.GetBoolValue()
boolval, ok := mv.GetBoolValue()
assert.True(t, boolval)
assert.True(t, ok)

mv = FromDeferredType("false")
boolval, ok = mv.GetBoolValue()
_, ok = mv.GetBoolValue()
assert.False(t, ok, "from-data-file \"false\" should infer to string")
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/mlrval/mlrval_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ func MlrvalDecodeFromJSON(decoder *json.Decoder) (
)
}

mv := FromPending()
// Will be assigned as an array or a map
var mv *Mlrval

if isArray {
mv = FromEmptyArray()

Expand All @@ -203,7 +205,6 @@ func MlrvalDecodeFromJSON(decoder *json.Decoder) (
}
mv.ArrayAppend(element)
}

} else {
mv = FromEmptyMap()

Expand Down

0 comments on commit 02bd534

Please sign in to comment.