diff --git a/lang/Makefile b/lang/Makefile index 63728482..5b2dc401 100644 --- a/lang/Makefile +++ b/lang/Makefile @@ -33,11 +33,8 @@ SHELL = /usr/bin/env bash all: build build: parser/lexer.nn.go parser/y.go interpolate/parse.generated.go - @# recursively run make in child dir named types - @$(MAKE) --quiet -C types clean: - $(MAKE) --quiet -C types clean @rm -f parser/lexer.nn.go parser/y.go parser/y.output interpolate/parse.generated.go || true parser/lexer.nn.go: parser/lexer.nex diff --git a/lang/ast/structs.go b/lang/ast/structs.go index 5de5648a..89539d35 100644 --- a/lang/ast/structs.go +++ b/lang/ast/structs.go @@ -3830,7 +3830,7 @@ func (obj *StmtProg) SetScope(scope *interfaces.Scope) error { } // If we don't do this deterministically the type unification errors can - // flip from `type error: Int != Str` to `type error: Str != Int` etc... + // flip from `type error: int != str` to `type error: str != int` etc... nodeOrder, err := orderingGraph.DeterministicTopologicalSort() // sorted! if err != nil { diff --git a/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.txtar b/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.txtar index e595301c..c4978b63 100644 --- a/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.txtar +++ b/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.txtar @@ -12,4 +12,4 @@ class c1($a, $b []str) { } } -- OUTPUT -- -# err: errUnify: unify error with: str("hello"): type error: List != Str +# err: errUnify: unify error with: str("hello"): type error: list != str diff --git a/lang/interpret_test/TestAstFunc2/fortytwoerror.txtar b/lang/interpret_test/TestAstFunc2/fortytwoerror.txtar index 87d99d32..5ddf0d72 100644 --- a/lang/interpret_test/TestAstFunc2/fortytwoerror.txtar +++ b/lang/interpret_test/TestAstFunc2/fortytwoerror.txtar @@ -15,4 +15,4 @@ test ["x",] { float32 => $b, } -- OUTPUT -- -# err: errUnify: unify error with: topLevel(func() { }): type error: Int != Float +# err: errUnify: unify error with: topLevel(func() { }): type error: int != float diff --git a/lang/interpret_test/TestAstFunc2/invalid-function-call.txtar b/lang/interpret_test/TestAstFunc2/invalid-function-call.txtar index b3afb8fa..a8e53130 100644 --- a/lang/interpret_test/TestAstFunc2/invalid-function-call.txtar +++ b/lang/interpret_test/TestAstFunc2/invalid-function-call.txtar @@ -10,4 +10,4 @@ print "msg" { msg => fmt.printf("notfn: %d", $x), } -- OUTPUT -- -# err: errUnify: unify error with: topLevel(singleton(int(42))): type error: Func != Int +# err: errUnify: unify error with: topLevel(singleton(int(42))): type error: func != int diff --git a/lang/interpret_test/TestAstFunc2/polymorphic-lambda.txtar b/lang/interpret_test/TestAstFunc2/polymorphic-lambda.txtar index 482a05e0..0ba5cb0a 100644 --- a/lang/interpret_test/TestAstFunc2/polymorphic-lambda.txtar +++ b/lang/interpret_test/TestAstFunc2/polymorphic-lambda.txtar @@ -17,4 +17,4 @@ $out2 = $add($val) # hellohello test [fmt.printf("%s + %s is %s", $val, $val, $out2),] {} # simple concat -- OUTPUT -- -# err: errUnify: unify error with: topLevel(singleton(func(x) { call:_operator(str("+"), var(x), var(x)) })): type error: Int != Str +# err: errUnify: unify error with: topLevel(singleton(func(x) { call:_operator(str("+"), var(x), var(x)) })): type error: int != str diff --git a/lang/interpret_test/TestAstFunc2/printfunificationerr0.txtar b/lang/interpret_test/TestAstFunc2/printfunificationerr0.txtar index 9b5e4717..ba82486b 100644 --- a/lang/interpret_test/TestAstFunc2/printfunificationerr0.txtar +++ b/lang/interpret_test/TestAstFunc2/printfunificationerr0.txtar @@ -2,4 +2,4 @@ import "fmt" test fmt.printf("%d%d", 42) {} # should not pass, missing second int -- OUTPUT -- -# err: errUnify: unify error with: call:fmt.printf(str("%d%d"), int(42)): type error: Str != List +# err: errUnify: unify error with: call:fmt.printf(str("%d%d"), int(42)): type error: str != list diff --git a/lang/interpret_test/TestAstFunc2/res1.txtar b/lang/interpret_test/TestAstFunc2/res1.txtar index 2404f47d..4dc3d623 100644 --- a/lang/interpret_test/TestAstFunc2/res1.txtar +++ b/lang/interpret_test/TestAstFunc2/res1.txtar @@ -3,4 +3,4 @@ test "t1" { stringptr => 42, # int, not str } -- OUTPUT -- -# err: errUnify: unify error with: int(42): type error: Str != Int +# err: errUnify: unify error with: int(42): type error: str != int diff --git a/lang/interpret_test/TestAstFunc2/scope-lambda-printf.txtar b/lang/interpret_test/TestAstFunc2/scope-lambda-printf.txtar index 22110a9e..7dfa5971 100644 --- a/lang/interpret_test/TestAstFunc2/scope-lambda-printf.txtar +++ b/lang/interpret_test/TestAstFunc2/scope-lambda-printf.txtar @@ -10,4 +10,4 @@ test "${name}" {} # TODO: I would expect that if the "%s" and "%d" swapped, that speculatively we # would be able to run this at compile time and know the result statically. -- OUTPUT -- -# err: errStream: func `printf@??????????` stopped before it was loaded: base kind does not match (Str != Int) +# err: errStream: func `printf@??????????` stopped before it was loaded: base kind does not match (str != int) diff --git a/lang/interpret_test/TestAstFunc2/test-monomorphic-bind.txtar b/lang/interpret_test/TestAstFunc2/test-monomorphic-bind.txtar index a1751059..2127badf 100644 --- a/lang/interpret_test/TestAstFunc2/test-monomorphic-bind.txtar +++ b/lang/interpret_test/TestAstFunc2/test-monomorphic-bind.txtar @@ -10,4 +10,4 @@ test "test2" { anotherstr => $id("hello"), } -- OUTPUT -- -# err: errUnify: unify error with: topLevel(singleton(func(x) { var(x) })): type error: Int != Str +# err: errUnify: unify error with: topLevel(singleton(func(x) { var(x) })): type error: int != str diff --git a/lang/interpret_test/TestAstFunc2/test-monomorphic-class-arg.txtar b/lang/interpret_test/TestAstFunc2/test-monomorphic-class-arg.txtar index 63c4891a..392a1e7a 100644 --- a/lang/interpret_test/TestAstFunc2/test-monomorphic-class-arg.txtar +++ b/lang/interpret_test/TestAstFunc2/test-monomorphic-class-arg.txtar @@ -12,4 +12,4 @@ class use_polymorphically($id) { } include use_polymorphically(func($x) {$x}) -- OUTPUT -- -# err: errUnify: unify error with: topLevel(singleton(func(x) { var(x) })): type error: Int != Str +# err: errUnify: unify error with: topLevel(singleton(func(x) { var(x) })): type error: int != str diff --git a/lang/interpret_test/TestAstFunc2/test-monomorphic-func-arg.txtar b/lang/interpret_test/TestAstFunc2/test-monomorphic-func-arg.txtar index adf3c7c3..73c378c5 100644 --- a/lang/interpret_test/TestAstFunc2/test-monomorphic-func-arg.txtar +++ b/lang/interpret_test/TestAstFunc2/test-monomorphic-func-arg.txtar @@ -10,4 +10,4 @@ test "test1" { anotherstr => use_polymorphically(func($x) {$x}), } -- OUTPUT -- -# err: errUnify: unify error with: param(id): type error: Int != Str +# err: errUnify: unify error with: param(id): type error: int != str diff --git a/lang/interpret_test/TestAstFunc2/test-monomorphic-lambda-arg.txtar b/lang/interpret_test/TestAstFunc2/test-monomorphic-lambda-arg.txtar index 30d3eebf..cbed5934 100644 --- a/lang/interpret_test/TestAstFunc2/test-monomorphic-lambda-arg.txtar +++ b/lang/interpret_test/TestAstFunc2/test-monomorphic-lambda-arg.txtar @@ -10,4 +10,4 @@ test "test1" { anotherstr => $use_polymorphically(func($x) {$x}), } -- OUTPUT -- -# err: errUnify: unify error with: param(id): type error: Int != Str +# err: errUnify: unify error with: param(id): type error: int != str diff --git a/lang/interpret_test/TestAstFunc2/unify-interpolate-edge1-fail.txtar b/lang/interpret_test/TestAstFunc2/unify-interpolate-edge1-fail.txtar index e155ff61..c18d5599 100644 --- a/lang/interpret_test/TestAstFunc2/unify-interpolate-edge1-fail.txtar +++ b/lang/interpret_test/TestAstFunc2/unify-interpolate-edge1-fail.txtar @@ -7,4 +7,4 @@ test "test" {} Test["${name}"] -> Test["test"] # must fail -- OUTPUT -- -# err: errUnify: unify error with: var(name): type error: Str != List +# err: errUnify: unify error with: var(name): type error: str != list diff --git a/lang/interpret_test/TestAstFunc2/unify-interpolate-edge2-fail.txtar b/lang/interpret_test/TestAstFunc2/unify-interpolate-edge2-fail.txtar index 1bacda88..3d3109c5 100644 --- a/lang/interpret_test/TestAstFunc2/unify-interpolate-edge2-fail.txtar +++ b/lang/interpret_test/TestAstFunc2/unify-interpolate-edge2-fail.txtar @@ -7,4 +7,4 @@ test "test" {} Test["test"] -> Test["${name}"] # must fail -- OUTPUT -- -# err: errUnify: unify error with: var(name): type error: Str != List +# err: errUnify: unify error with: var(name): type error: str != list diff --git a/lang/interpret_test/TestAstFunc2/unify-interpolate-res-fail.txtar b/lang/interpret_test/TestAstFunc2/unify-interpolate-res-fail.txtar index b49640f8..6e18badc 100644 --- a/lang/interpret_test/TestAstFunc2/unify-interpolate-res-fail.txtar +++ b/lang/interpret_test/TestAstFunc2/unify-interpolate-res-fail.txtar @@ -5,4 +5,4 @@ $name = ["a", "bb", "ccc",] test "${name}" {} # must fail -- OUTPUT -- -# err: errUnify: unify error with: var(name): type error: Str != List +# err: errUnify: unify error with: var(name): type error: str != list diff --git a/lang/interpret_test/TestAstFunc2/very-complex-example.txtar b/lang/interpret_test/TestAstFunc2/very-complex-example.txtar index 4e8a1dd0..d88c88ea 100644 --- a/lang/interpret_test/TestAstFunc2/very-complex-example.txtar +++ b/lang/interpret_test/TestAstFunc2/very-complex-example.txtar @@ -75,4 +75,4 @@ $foo = iter.map([$id1, $id2,], $generate) $name = $foo[0] || "fail" test "${name}" {} -- OUTPUT -- -# err: errUnify: unify error with: param(idn): type error: Str != Int +# err: errUnify: unify error with: param(idn): type error: str != int diff --git a/lang/types/Makefile b/lang/types/Makefile deleted file mode 100644 index 94e9ce88..00000000 --- a/lang/types/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -# Mgmt -# Copyright (C) 2013-2024+ James Shubin and the project contributors -# Written by James Shubin and the project contributors -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Additional permission under GNU GPL version 3 section 7 -# -# If you modify this program, or any covered work, by linking or combining it -# with embedded mcl code and modules (and that the embedded mcl code and -# modules which link with this program, contain a copy of their source code in -# the authoritative form) containing parts covered by the terms of any other -# license, the licensors of this program grant you additional permission to -# convey the resulting work. Furthermore, the licensors of this program grant -# the original author, James Shubin, additional permission to update this -# additional permission if he deems it necessary to achieve the goals of this -# additional permission. - -SHELL = /usr/bin/env bash -.PHONY: all build clean - -all: build - -build: kind_stringer.go - -clean: - @rm -f kind_stringer.go || true - -kind_stringer.go: type.go - @echo "Generating: type kind strings..." - @# stringer fails if run from GOROOT. - @# see: https://github.com/golang/go/issues/31843 - @if which stringer | grep `go env GOROOT`; then \ - echo "stringer cannot run from GOROOT"; \ - exit 1; \ - fi - @go generate diff --git a/lang/types/stringer.go b/lang/types/stringer.go new file mode 100644 index 00000000..61b80922 --- /dev/null +++ b/lang/types/stringer.go @@ -0,0 +1,64 @@ +// Mgmt +// Copyright (C) 2013-2024+ James Shubin and the project contributors +// Written by James Shubin and the project contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// Additional permission under GNU GPL version 3 section 7 +// +// If you modify this program, or any covered work, by linking or combining it +// with embedded mcl code and modules (and that the embedded mcl code and +// modules which link with this program, contain a copy of their source code in +// the authoritative form) containing parts covered by the terms of any other +// license, the licensors of this program grant you additional permission to +// convey the resulting work. Furthermore, the licensors of this program grant +// the original author, James Shubin, additional permission to update this +// additional permission if he deems it necessary to achieve the goals of this +// additional permission. + +package types + +// String returns a representation for the kind. These are the strings seen in +// most type unification errors. We don't use stringer since it would capitalize +// them. +func (obj Kind) String() string { + switch obj { + case KindNil: + return "nil" + case KindBool: + return "bool" + case KindStr: + return "str" + case KindInt: + return "int" + case KindFloat: + return "float" + case KindList: + return "list" + case KindMap: + return "map" + case KindStruct: + return "struct" + case KindFunc: + return "func" + case KindVariant: + return "variant" + + case KindUnification: + return "unification" + + default: + panic("unknown kind") + } +} diff --git a/lang/types/type.go b/lang/types/type.go index c29ab6e9..836236e5 100644 --- a/lang/types/type.go +++ b/lang/types/type.go @@ -59,13 +59,12 @@ var ( TypeVariant = NewType("variant") ) -//go:generate stringer -type=Kind -trimprefix=Kind -output=kind_stringer.go - // The Kind represents the base type of each value. type Kind int // this used to be called Type // Each Kind represents a type in the language type system. const ( + // NOTE: Make sure you add entries to stringer.go if you add something. KindNil Kind = iota KindBool KindStr diff --git a/test/test-golint.sh b/test/test-golint.sh index 21b479ff..ae8166ca 100755 --- a/test/test-golint.sh +++ b/test/test-golint.sh @@ -27,7 +27,7 @@ if [ "$COMMITS" != "" ] && [ "$COMMITS" -gt "1" ]; then fi # find all go files, exluding temporary directories and generated files -LINT=$(find * -maxdepth 9 -iname '*.go' -not -path 'old/*' -not -path 'tmp/*' -not -path 'lang/parser/y.go' -not -path 'lang/parser/lexer.nn.go' -not -path 'lang/interpolate/parse.generated.go' -not -path 'lang/types/kind_stringer.go' -not -path 'vendor/*' -exec golint {} \;) # current golint output +LINT=$(find * -maxdepth 9 -iname '*.go' -not -path 'old/*' -not -path 'tmp/*' -not -path 'lang/parser/y.go' -not -path 'lang/parser/lexer.nn.go' -not -path 'lang/interpolate/parse.generated.go' -not -path 'vendor/*' -exec golint {} \;) # current golint output COUNT=`echo -e "$LINT" | wc -l` # number of golint problems in current branch [ "$LINT" = "" ] && echo PASS && exit # everything is "perfect" diff --git a/test/test-gometalinter.sh b/test/test-gometalinter.sh index f15dd3c9..327b999e 100755 --- a/test/test-gometalinter.sh +++ b/test/test-gometalinter.sh @@ -47,7 +47,6 @@ gml="$gml --enable=misspell" # TODO: at least until https://github.com/alecthomas/gometalinter/issues/270 gml="$gml --exclude=lang/parser/lexer.nn.go" gml="$gml --exclude=lang/parser/y.go" -gml="$gml --exclude=lang/types/kind_stringer.go" gml="$gml --exclude=lang/interpolate/parse.generated.go" gometalinter="$gml" # final