Exemplo n.º 1
0
        private static IDictionary <TypeVariable, IHerbrandObject> GetOutput(IDictionary <TypeVariable, IHerbrandObject> input)
        {
            var chosenAlternative = new Mock <IDictionary <Clause, int> >();
            var solution          = new Solution()
            {
                TypeVariableMapping = input, ChosenAlternative = chosenAlternative.Object
            };

            var normalizedSolution = SolutionNormalizer.Normalize(solution);

            chosenAlternative.VerifyNoOtherCalls();
            Assert.ReferenceEquals(normalizedSolution.ChosenAlternative, chosenAlternative);

            return(normalizedSolution.TypeVariableMapping);
        }
Exemplo n.º 2
0
            public void LinkTypes(Node root)
            {
                this.ProcessChildren(root);

                try
                {
                    Solution solution           = new Solver(this.clauses).Solve();
                    Solution normalizedSolution = SolutionNormalizer.Normalize(solution);
                    this.SubstituteSolution(root, normalizedSolution);
                }
                catch (Exception ex) when(ex is TypeCheckerException || ex is SolutionNormalizerException)
                {
                    this.diagnostics.Add(new Diagnostic(
                                             DiagnosticStatus.Error,
                                             TypeAssignmentDiagnostic,
                                             $"Could not assign types: {ex.Message}",
                                             new List <Lexer.Range>()));
                    throw new TypeCheckerException("Could not assign types", ex);
                }
            }