Skip to content

Commit ed3c1c1

Browse files
committed
Inspected all the script execution errors to confirm which ones are expected and to fix those that were not.
Signed-off-by: Dean Wampler <[email protected]>
1 parent 11f56d5 commit ed3c1c1

File tree

23 files changed

+133
-105
lines changed

23 files changed

+133
-105
lines changed

check-scripts.sh

Lines changed: 68 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,48 @@
33
default_dirs=( "src/script/scala" )
44
out_root="target/script-tests"
55
out_ext="out"
6+
timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
67
expected_errors_in=(
7-
src/script/scala/progscala3/appdesign/Deprecated.scala
8-
src/script/scala/progscala3/patternmatching/MatchExhaustive.scala
9-
src/script/scala/progscala3/patternmatching/MatchSurprise.scala
8+
109
src/script/scala/progscala3/IndentationSyntax.scala
11-
src/script/scala/progscala3/contexts/typeclass/TypeClassSubtypingProblems.scala
10+
src/script/scala/progscala3/appdesign/Deprecated.scala
11+
src/script/scala/progscala3/basicoop/MatchableOpaque.scala
12+
src/script/scala/progscala3/collections/MultiMap.scala
13+
src/script/scala/progscala3/contexts/ImplicitEvidence.scala
14+
src/script/scala/progscala3/contexts/ImplicitNotFound.scala
15+
src/script/scala/progscala3/contexts/MatchGivens.scala
1216
src/script/scala/progscala3/contexts/SeqUnzip.scala
13-
src/script/scala/progscala3/meta/inline/Recursive.scala
14-
src/script/scala/progscala3/meta/inline/Overrides.scala
17+
src/script/scala/progscala3/dynamic/SelectableSQL.scala
1518
src/script/scala/progscala3/meta/compiletime/RequireConst.scala
1619
src/script/scala/progscala3/meta/compiletime/SummonAll.scala
17-
src/script/scala/progscala3/rounding/TypeErasureProblem.scala
20+
src/script/scala/progscala3/meta/inline/ConditionalMatch.scala
21+
src/script/scala/progscala3/meta/inline/Overrides.scala
22+
src/script/scala/progscala3/meta/inline/Recursive.scala
23+
src/script/scala/progscala3/objectsystem/variance/MutableVariance.scala
24+
src/script/scala/progscala3/patternmatching/Matchable.scala
25+
src/script/scala/progscala3/patternmatching/MatchExhaustive.scala
26+
src/script/scala/progscala3/patternmatching/MatchForFiltering.scala
27+
src/script/scala/progscala3/patternmatching/MatchSurprise.scala
28+
src/script/scala/progscala3/patternmatching/MatchTypesErasure.scala
29+
src/script/scala/progscala3/patternmatching/UnapplySingleValue2.scala
1830
src/script/scala/progscala3/rounding/InfixMethod.scala
31+
src/script/scala/progscala3/rounding/InfixType.scala
32+
src/script/scala/progscala3/rounding/TypeErasureProblem.scala
1933
src/script/scala/progscala3/typelessdomore/Human.scala
20-
src/script/scala/progscala3/typelessdomore/RepeatedParameters.scala
2134
src/script/scala/progscala3/typelessdomore/MethodBroadInference.scala
22-
src/script/scala/progscala3/typelessdomore/MethodRecursiveReturn.scala
2335
src/script/scala/progscala3/typelessdomore/MethodNestedReturn.scala
24-
src/script/scala/progscala3/basicoop/MatchableOpaque.scala
36+
src/script/scala/progscala3/typelessdomore/MethodRecursiveReturn.scala
37+
src/script/scala/progscala3/typelessdomore/RepeatedParameters.scala
38+
src/script/scala/progscala3/typesystem/bounds/ViewToContextBounds.scala
39+
src/script/scala/progscala3/typesystem/deptypes/DependentTypes.scala
40+
src/script/scala/progscala3/typesystem/deptypes/DependentTypesBounds.scala
41+
src/script/scala/progscala3/typesystem/deptypes/DependentTypesSimple.scala
42+
src/script/scala/progscala3/typesystem/intersectionunion/Intersection.scala
43+
src/script/scala/progscala3/typesystem/intersectionunion/Union.scala
44+
src/script/scala/progscala3/typesystem/matchtypes/MatchTypes2.scala
2545
src/script/scala/progscala3/typesystem/typepaths/TypePath.scala
2646
src/script/scala/progscala3/typesystem/valuetypes/SingletonTypes.scala
27-
src/script/scala/progscala3/patternmatching/MatchTypesErasure.scala
28-
src/script/scala/progscala3/patternmatching/MatchForFiltering.scala
29-
src/script/scala/progscala3/collections/MultiMap.scala
47+
src/script/scala/progscala3/typesystem/valuetypes/TypeProjection.scala
3048
)
3149

3250
error() {
@@ -46,18 +64,19 @@ are files with @main methods under src/main that can be interpreted as Scala 3
4664
argument.
4765
4866
So, this bash script starts the REPL (using "sbt console") for each file and then
49-
uses :load to load the file. The output is written to
67+
uses :load to load the file. The output for that console sessions is written to
5068
$out_root/path/to/file.$out_ext.
5169
70+
A list of files with errors or warnings is written to $out_root/errors-$timestamp.log.
71+
5272
The following files are known to throw errors intentionally:
5373
$(for f in ${expected_errors_in[@]}; do echo " $f"; done)
5474
55-
Failures for these known files are ignored. In some of them, you'll see a comment
56-
on the same line, like "// ERROR" or "// COMPILATION ERROR", which are easier to
57-
spot when looking at error messages. In other cases, you have to look at the book
58-
discussion to see if the error is expected. Unfortunately, this means that any
59-
unexpected errors in these files will be missed, unless you inspect the output
60-
when running them!
75+
Failures for these known files are ignored, but logged in $out_root/errors-$timestamp.log.
76+
In most of them, you'll see a comment on the same line, like "// ERROR" or "// COMPILATION ERROR",
77+
which are easier to spot when looking at error messages. In the rest of the cases, you have to
78+
look at the book discussion to see if the error is expected. Unfortunately, this means that any
79+
unexpected errors in these files will be missed, unless you inspect the output carefully!
6180
6281
For finding unexpected errors, the console output is searched for errors by looking
6382
for any of the following lines near the end (where N=2+):
@@ -67,7 +86,7 @@ N warnings found
6786
1 error found
6887
N errors found
6988
70-
HOWEVER, to be really safe, all the outputs should still be inspected manually.
89+
** HOWEVER, to be really safe, all the outputs should still be inspected manually. **
7190
7291
Usage: $0 [-h|--help] [-v|--verbose] [-c|--clean] [-n|--no-exec] [dir ...]
7392
Where:
@@ -128,44 +147,47 @@ then
128147
[[ -n "$out_root" ]] && rm -rf "$out_root" # safety check!
129148
fi
130149

150+
151+
error_log="$out_root/errors-$timestamp.log"
152+
rm -f $error_log
153+
154+
print_count() {
155+
let count=$1; shift
156+
file=$1; shift
157+
out=$1; shift
158+
message="$1"; shift
159+
printf '%5d: %s %s %s\n' $count "$file" "$out" "$message" >> $error_log
160+
}
161+
131162
count_problem() {
132-
problem=$1
133-
script=$2
134-
out=$3
135-
let count=$(grep -cE "^.+ $problem? found$" "$out" | sed -e "s/ $problem.*//")
136-
case $count in
137-
0)
138-
# do nothing
139-
;;
140-
1)
141-
echo "ERROR: 1 ${problem} found in $script ($out)"
142-
;;
143-
*)
144-
echo "ERROR: $count ${problem}s found in $script ($out)"
145-
;;
146-
esac
163+
script=$1
164+
out=$2
165+
let count=$(grep -cE "^.+ (error|warning)s? found$" "$out")
166+
[[ $count -gt 0 ]] && print_count $count $script $out
147167
return $count
148168
}
149169

150170
report() {
151171
let status=$1
152172
script=$2
153173
out=$3
174+
for skip in ${expected_errors_in[@]}
175+
do
176+
if [[ "$skip" = "$script" ]]
177+
then
178+
print_count 0 "$script" "$out" "NOTE: because of known deliberate errors, unexpected errors might be missed!"
179+
return 0
180+
fi
181+
done
154182
let error_count=0
155183
if [[ $status -ne 0 ]]
156184
then
157185
echo "ERROR: $script failed! ($out)"
158186
let error_count+=1
159187
fi
160-
for skip in ${expected_errors_in[@]}
161-
do
162-
[[ "$skip" = "$script" ]] && return $error_count
163-
done
164-
count_problem 'warning' "$script" "$out"
165-
let error_count+=$?
166-
count_problem 'error' "$script" "$out"
188+
count_problem "$script" "$out"
167189
let error_count+=$?
168-
$VERBOSE && cat "$out"
190+
# $VERBOSE && cat "$out"
169191
return $error_count
170192
}
171193

@@ -214,7 +236,8 @@ then
214236
rm -f "$problem_count"
215237
if [[ $total_problem_count -gt 0 ]]
216238
then
217-
echo "ERROR: $total_problem_count issues found."
239+
echo "ERROR: $total_problem_count issues found. See $error_log"
240+
print_count $total_problem_count $error_log "" "issues found!"
218241
exit 1
219242
fi
220243
fi

src/script/scala/progscala3/IndentationSyntax.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ end while
5252
// Match expression
5353
0 match
5454
case 0 => println("zero")
55-
case _ => println("other value")
55+
case _ => println("other value") // ERROR: "Match case Unreachable Warning"
5656
end match
5757

5858
// Partially-defined function

src/script/scala/progscala3/basicoop/DollarsPercentagesOpaque.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ val gross = Dollars(10000.0)
3737
val taxes = Percentage(0.1)
3838
val salary1 = Salary(gross, taxes)
3939
val net1 = salary1.net
40-
val salary2 = Salary(taxes, gross) // Won't compile!
40+
val salary2 = Salary(taxes, gross) // ERROR Won't compile!
4141
// end::usage[]

src/script/scala/progscala3/basicoop/GoodBad.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
object OBad:
44
def m(seq: Seq[Int]): String = seq.mkString("|")
5-
def m(seq: Seq[String]): String = seq.mkString(",")
5+
def m(seq: Seq[String]): String = seq.mkString(",") // ERROR
66

77
trait TGood:
88
def member(suffix: String): String
99
val member: String
1010

1111
trait TBad:
1212
def member: String
13-
val member: String
13+
val member: String // ERROR

src/script/scala/progscala3/basicoop/tagging/Tags.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ val o: Ordering[Double] = implicitly
1414
val om: Ordering[Double @@ Meter] = o.tags
1515
om.compare(x, x)
1616
om.compare(x, y) // Compilation Error!
17-
xs.min(om)
18-
xs.min(o) // Compilation Error!
17+
xs.min(using om)
18+
xs.min(using o) // Compilation Error!

src/script/scala/progscala3/basicoop/tagging/Tags2.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ val o: Ordering[Double] = implicitly
1414
val om: Ordering[Double @@ Meter] = o.tags
1515
om.compare(x, x)
1616
om.compare(x, y) // Compilation Error!
17-
xs.min(om)
18-
xs.min(o) // Compilation Error!
17+
xs.min(using om)
18+
xs.min(using o) // Compilation Error!

src/script/scala/progscala3/contexts/ExtensionMethodScoping.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ val s = "Hello World!"
55
trait T:
66
extension (s: String) def LOUD: String = s.toUpperCase
77

8-
s.LOUD // error; LOUD not in scope.
8+
s.LOUD // ERROR; LOUD not in scope.
99

1010
object S2 extends T:
1111
def loud(s: String): String = s.LOUD
@@ -15,7 +15,7 @@ S2.loud(s)
1515
object S2:
1616
extension (s: String) def soft: String = s.toLowerCase
1717

18-
s.soft
18+
s.soft // ERROR; soft not in scope.
1919

2020
import S2.soft
2121
s.soft

src/script/scala/progscala3/contexts/MatchGivens.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ def useWitness(using Witness): String = summon[Witness].toString // <2>
99
// end::definitions[]
1010

1111
// tag::usage[]
12-
useWitness // <1>
12+
useWitness // ERROR // <1>
1313

1414
for given Witness <- Seq(IntWitness, StringWitness) // <2>
1515
do println(useWitness)
1616

17-
useWitness // <3>
17+
useWitness // ERROR // <3>
1818

1919
Seq(IntWitness -> "Int", StringWitness -> "String") foreach { // <4>
2020
case (witness @ given Witness, y) => println(s"witness: $useWitness -> $y")
2121
}
2222

23-
useWitness // <5>
23+
useWitness // ERROR // <5>
2424
// end::usage[]

src/script/scala/progscala3/contexts/UsingClauses.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
case class SortableSeq[A](seq: Seq[A]):
55
def sortBy1a[B](transform: A => B)(using o: Ordering[B]): SortableSeq[A] =
6-
SortableSeq(seq.sortBy(transform)(o))
6+
SortableSeq(seq.sortBy(transform)(using o))
77

88
def sortBy1b[B](transform: A => B)(using Ordering[B]): SortableSeq[A] =
9-
SortableSeq(seq.sortBy(transform)(summon[Ordering[B]]))
9+
SortableSeq(seq.sortBy(transform)(using summon[Ordering[B]]))
1010

1111
def sortBy2[B : Ordering](transform: A => B): SortableSeq[A] =
12-
SortableSeq(seq.sortBy(transform)(summon[Ordering[B]]))
12+
SortableSeq(seq.sortBy(transform)(using summon[Ordering[B]]))
1313
// end::definitions[]
1414

1515
// tag::defaultOrdering[]

src/script/scala/progscala3/meta/compiletime/SummonAll.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ given c: C()
77
given d: D()
88

99
summonAll[C *: D *: EmptyTuple]
10-
summonAll[C *: D *: E *: EmptyTuple] // <1>
10+
summonAll[C *: D *: E *: EmptyTuple] // ERROR // <1>

0 commit comments

Comments
 (0)