Skip to content

Commit 6df70ff

Browse files
[Compiler] Refactoring.
git-svn-id: https://nemerle.googlecode.com/svn/nemerle/trunk@9907 c8a6711f-211a-0410-a8d5-2f220496d6d1
1 parent ba5576e commit 6df70ff

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

ncc/typing/Typer-PatternTyper.n

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -358,33 +358,28 @@ namespace Nemerle.Compiler
358358
}
359359
else match (matched_value_type.Hint)
360360
{
361-
// if we expecte to match on a class, transform the pattern
361+
// if we expect matching on a class, transform the pattern
362362
// to include field names
363363
| Some (FixedType.Class (ti, _)) =>
364364
def flags = BindingFlags.DeclaredOnly %| BindingFlags.Public %| BindingFlags.Instance;
365365
def mems = ti.GetFields(flags).Filter(withoutIgnoreFieldAttribute);
366366
def names = mems.Map(_.Name);
367-
if (names.Length == pats.Length)
367+
match(pats.Length)
368368
{
369-
if (pats.Length == 0)
370-
{
371-
ReportError(messenger, "pattern can't matchs 0 values.");
369+
| 0 =>
370+
ReportError(messenger, "pattern can't match 0 values");
372371
Pattern.Error()
373-
}
374-
else
375-
{
372+
373+
| n when n == names.Length =>
376374
def assigns = NList.Map2(names, pats, (n, p) => PT.PExpr.Assign (PT.PExpr.Ref(PT.Name(n)), p));
377375
TypeTuplePattern(matched_value_type, assigns)
378-
}
379-
}
380-
else
381-
{
382-
ReportError(messenger, $"pattern matches $(pats.Length) values, while the type `$(ti)' has $(names.Length) fields");
383-
Pattern.Error()
376+
377+
| n =>
378+
ReportError(messenger, $"pattern matches $n values, while the type `$ti' has $(names.Length) fields");
379+
Pattern.Error()
384380
}
385-
386-
| Some (FixedType.Tuple (types))
387-
when types.Length != pats.Length =>
381+
382+
| Some (FixedType.Tuple (types)) when types.Length != pats.Length =>
388383
ReportError (messenger,
389384
$ "pattern matches $(pats.Length)-tuples, "
390385
"while the value matched is a "

0 commit comments

Comments
 (0)