Skip to content

Commit

Permalink
Add tests for PR #340 Issue #276
Browse files Browse the repository at this point in the history
  • Loading branch information
quark17 committed Apr 12, 2021
1 parent 4ffc934 commit bd141b5
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 0 deletions.
5 changes: 5 additions & 0 deletions testsuite/bsc.bugs/github/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# for "make clean" to work everywhere

CONFDIR = $(realpath ../..)

include $(CONFDIR)/clean.mk
5 changes: 5 additions & 0 deletions testsuite/bsc.bugs/github/gh276/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# for "make clean" to work everywhere

CONFDIR = $(realpath ../../..)

include $(CONFDIR)/clean.mk
5 changes: 5 additions & 0 deletions testsuite/bsc.bugs/github/gh276/SuggestStringOf_NoCon.bsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
typedef "Foo" Name;

function Bool isName (String x);
return (Name == x);
endfunction
Original file line number Diff line number Diff line change
@@ -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?
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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?
5 changes: 5 additions & 0 deletions testsuite/bsc.bugs/github/gh276/SuggestValueOf_NoCon.bsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
typedef 32 DataWidth;

function Bool is64 (Bit#(8) x);
return (DataWidth == 64);
endfunction
Original file line number Diff line number Diff line change
@@ -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?
9 changes: 9 additions & 0 deletions testsuite/bsc.bugs/github/gh276/SuggestValueOf_OneCon.bsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
typedef union tagged {
Bit#(16) DataWidth;
} T1;

typedef 32 DataWidth;

function Integer getDataWidth();
return DataWidth;
endfunction
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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?
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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'
43 changes: 43 additions & 0 deletions testsuite/bsc.bugs/github/gh276/gh276.exp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bd141b5

Please sign in to comment.