From bd141b505394edc5a4bdd3db442a9b0a8c101f0f Mon Sep 17 00:00:00 2001 From: Julie Schwartz Date: Mon, 12 Apr 2021 02:05:30 -0400 Subject: [PATCH] Add tests for PR #340 Issue #276 --- testsuite/bsc.bugs/github/Makefile | 5 +++ testsuite/bsc.bugs/github/gh276/Makefile | 5 +++ .../github/gh276/SuggestStringOf_NoCon.bsv | 5 +++ ...SuggestStringOf_NoCon.bsv.bsc-out.expected | 4 ++ .../SuggestStringOf_TwoCon_IntegerContext.bsv | 13 ++++++ ...TwoCon_IntegerContext.bsv.bsc-out.expected | 4 ++ .../github/gh276/SuggestValueOf_NoCon.bsv | 5 +++ .../SuggestValueOf_NoCon.bsv.bsc-out.expected | 4 ++ .../github/gh276/SuggestValueOf_OneCon.bsv | 9 ++++ ...SuggestValueOf_OneCon.bsv.bsc-out.expected | 11 +++++ .../SuggestValueOf_TwoCon_IntegerContext.bsv | 13 ++++++ ...TwoCon_IntegerContext.bsv.bsc-out.expected | 4 ++ .../SuggestValueOf_TwoCon_PolyContext.bsv | 14 ++++++ ...Of_TwoCon_PolyContext.bsv.bsc-out.expected | 4 ++ testsuite/bsc.bugs/github/gh276/gh276.exp | 43 +++++++++++++++++++ 15 files changed, 143 insertions(+) create mode 100644 testsuite/bsc.bugs/github/Makefile create mode 100644 testsuite/bsc.bugs/github/gh276/Makefile create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestStringOf_NoCon.bsv create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestStringOf_NoCon.bsv.bsc-out.expected create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestStringOf_TwoCon_IntegerContext.bsv create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestStringOf_TwoCon_IntegerContext.bsv.bsc-out.expected create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestValueOf_NoCon.bsv create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestValueOf_NoCon.bsv.bsc-out.expected create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestValueOf_OneCon.bsv create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestValueOf_OneCon.bsv.bsc-out.expected create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_IntegerContext.bsv create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_IntegerContext.bsv.bsc-out.expected create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_PolyContext.bsv create mode 100644 testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_PolyContext.bsv.bsc-out.expected create mode 100644 testsuite/bsc.bugs/github/gh276/gh276.exp diff --git a/testsuite/bsc.bugs/github/Makefile b/testsuite/bsc.bugs/github/Makefile new file mode 100644 index 000000000..b953e8132 --- /dev/null +++ b/testsuite/bsc.bugs/github/Makefile @@ -0,0 +1,5 @@ +# for "make clean" to work everywhere + +CONFDIR = $(realpath ../..) + +include $(CONFDIR)/clean.mk diff --git a/testsuite/bsc.bugs/github/gh276/Makefile b/testsuite/bsc.bugs/github/gh276/Makefile new file mode 100644 index 000000000..607fb8db7 --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/Makefile @@ -0,0 +1,5 @@ +# for "make clean" to work everywhere + +CONFDIR = $(realpath ../../..) + +include $(CONFDIR)/clean.mk diff --git a/testsuite/bsc.bugs/github/gh276/SuggestStringOf_NoCon.bsv b/testsuite/bsc.bugs/github/gh276/SuggestStringOf_NoCon.bsv new file mode 100644 index 000000000..cc6faf18a --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestStringOf_NoCon.bsv @@ -0,0 +1,5 @@ +typedef "Foo" Name; + +function Bool isName (String x); + return (Name == x); +endfunction diff --git a/testsuite/bsc.bugs/github/gh276/SuggestStringOf_NoCon.bsv.bsc-out.expected b/testsuite/bsc.bugs/github/gh276/SuggestStringOf_NoCon.bsv.bsc-out.expected new file mode 100644 index 000000000..929a26ce9 --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestStringOf_NoCon.bsv.bsc-out.expected @@ -0,0 +1,4 @@ +checking package dependencies +compiling SuggestStringOf_NoCon.bsv +Error: "SuggestStringOf_NoCon.bsv", line 4, column 12: (T0003) + Unbound constructor `Name'. Perhaps `stringOf' is missing? diff --git a/testsuite/bsc.bugs/github/gh276/SuggestStringOf_TwoCon_IntegerContext.bsv b/testsuite/bsc.bugs/github/gh276/SuggestStringOf_TwoCon_IntegerContext.bsv new file mode 100644 index 000000000..1ac3c1c51 --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestStringOf_TwoCon_IntegerContext.bsv @@ -0,0 +1,13 @@ +typedef union tagged { + Bit#(16) DataWidth; +} T1; + +typedef union tagged { + Bit#(8) DataWidth; +} T2; + +typedef "Foo" Name; + +function String getName(); + return Name; +endfunction diff --git a/testsuite/bsc.bugs/github/gh276/SuggestStringOf_TwoCon_IntegerContext.bsv.bsc-out.expected b/testsuite/bsc.bugs/github/gh276/SuggestStringOf_TwoCon_IntegerContext.bsv.bsc-out.expected new file mode 100644 index 000000000..d40ab9000 --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestStringOf_TwoCon_IntegerContext.bsv.bsc-out.expected @@ -0,0 +1,4 @@ +checking package dependencies +compiling SuggestStringOf_TwoCon_IntegerContext.bsv +Error: "SuggestStringOf_TwoCon_IntegerContext.bsv", line 12, column 11: (T0003) + Unbound constructor `Name'. Perhaps `stringOf' is missing? diff --git a/testsuite/bsc.bugs/github/gh276/SuggestValueOf_NoCon.bsv b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_NoCon.bsv new file mode 100644 index 000000000..9fabf43ee --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_NoCon.bsv @@ -0,0 +1,5 @@ +typedef 32 DataWidth; + +function Bool is64 (Bit#(8) x); + return (DataWidth == 64); +endfunction diff --git a/testsuite/bsc.bugs/github/gh276/SuggestValueOf_NoCon.bsv.bsc-out.expected b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_NoCon.bsv.bsc-out.expected new file mode 100644 index 000000000..bdd57cc5e --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_NoCon.bsv.bsc-out.expected @@ -0,0 +1,4 @@ +checking package dependencies +compiling SuggestValueOf_NoCon.bsv +Error: "SuggestValueOf_NoCon.bsv", line 4, column 12: (T0003) + Unbound constructor `DataWidth'. Perhaps `valueOf' is missing? diff --git a/testsuite/bsc.bugs/github/gh276/SuggestValueOf_OneCon.bsv b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_OneCon.bsv new file mode 100644 index 000000000..7235c7be4 --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_OneCon.bsv @@ -0,0 +1,9 @@ +typedef union tagged { + Bit#(16) DataWidth; +} T1; + +typedef 32 DataWidth; + +function Integer getDataWidth(); + return DataWidth; +endfunction diff --git a/testsuite/bsc.bugs/github/gh276/SuggestValueOf_OneCon.bsv.bsc-out.expected b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_OneCon.bsv.bsc-out.expected new file mode 100644 index 000000000..6ee0aff14 --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_OneCon.bsv.bsc-out.expected @@ -0,0 +1,11 @@ +checking package dependencies +compiling SuggestValueOf_OneCon.bsv +Error: "SuggestValueOf_OneCon.bsv", line 8, column 11: (T0144) + Wrong number of arguments in the partial application of the following + constructor: + SuggestValueOf_OneCon::DataWidth + The constructor expects 1 arguments and was used with 0 arguments, leaving 1 + unfilled, however a function was not expected. + The expected type is: + Integer + diff --git a/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_IntegerContext.bsv b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_IntegerContext.bsv new file mode 100644 index 000000000..2c35827e5 --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_IntegerContext.bsv @@ -0,0 +1,13 @@ +typedef union tagged { + Bit#(16) DataWidth; +} T1; + +typedef union tagged { + Bit#(8) DataWidth; +} T2; + +typedef 32 DataWidth; + +function Integer getDataWidth(); + return DataWidth; +endfunction diff --git a/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_IntegerContext.bsv.bsc-out.expected b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_IntegerContext.bsv.bsc-out.expected new file mode 100644 index 000000000..538ea487f --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_IntegerContext.bsv.bsc-out.expected @@ -0,0 +1,4 @@ +checking package dependencies +compiling SuggestValueOf_TwoCon_IntegerContext.bsv +Error: "SuggestValueOf_TwoCon_IntegerContext.bsv", line 12, column 11: (T0003) + Unbound constructor `DataWidth'. Perhaps `valueOf' is missing? diff --git a/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_PolyContext.bsv b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_PolyContext.bsv new file mode 100644 index 000000000..de13dafc7 --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_PolyContext.bsv @@ -0,0 +1,14 @@ +typedef union tagged { + Bit#(16) DataWidth; +} T1; + +typedef union tagged { + Bit#(8) DataWidth; +} T2; + +typedef 32 DataWidth; + +function Bool is64 (Integer x); + // The expected type for DataWidth is a variable because '==' is overloaded + return (DataWidth == 64); +endfunction diff --git a/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_PolyContext.bsv.bsc-out.expected b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_PolyContext.bsv.bsc-out.expected new file mode 100644 index 000000000..4172543d2 --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/SuggestValueOf_TwoCon_PolyContext.bsv.bsc-out.expected @@ -0,0 +1,4 @@ +checking package dependencies +compiling SuggestValueOf_TwoCon_PolyContext.bsv +Error: "SuggestValueOf_TwoCon_PolyContext.bsv", line 13, column 12: (T0019) + Constructor `DataWidth' is not disambiguated by type `_tctyvar1004' diff --git a/testsuite/bsc.bugs/github/gh276/gh276.exp b/testsuite/bsc.bugs/github/gh276/gh276.exp new file mode 100644 index 000000000..139bd89f7 --- /dev/null +++ b/testsuite/bsc.bugs/github/gh276/gh276.exp @@ -0,0 +1,43 @@ + +# GitHub Issue #276 +# +# Test BSC error messages when the user forgets to apply 'valueOf' +# (or 'stringOf') to a type name, which BSC then interprets as a +# constructor name + +proc do_test { filename } { + compile_fail $filename + compare_file [make_bsc_output_name $filename] +} + +# If there is no constructor by the same name as the type, +# BSC reports an unbound constructor error (T0003) +# and adds a message suggesting 'valueOf' +# +do_test SuggestValueOf_NoCon.bsv +do_test SuggestStringOf_NoCon.bsv + +# If there is one constructor by the same name as the type, +# BSC assumes the user meant that one, and uses its type. +# This likely results in a type mismatch error, because the +# constructor expects an argument. +# This message will not suggest that 'valueOf' is missing. +# +do_test SuggestValueOf_OneCon.bsv + +# If there is more than one constructor by the same name as the type, +# and the context expects a concrete type, then BSC will pick the +# constructor with that return type. Likely finding none, BSC will +# report an unbound constructor error (T0003) and add a message +# suggesting 'valueOf' +# +do_test SuggestValueOf_TwoCon_IntegerContext.bsv +do_test SuggestStringOf_TwoCon_IntegerContext.bsv + +# If there is more than on constructor by the same name as the type, +# but the context does not expect a concrete type (is polymorphic), +# then BSC will report an unambiguous constructor error (T0019). +# This message will not suggest that 'valueOf' is missing. +# +do_test SuggestValueOf_TwoCon_PolyContext.bsv +