Skip to content

Commit

Permalink
Fix bug with import type mismatch with export
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Oct 1, 2019
1 parent 2412c37 commit 03c6582
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.overture.ast.analysis.AnalysisAdaptor;
import org.overture.ast.analysis.AnswerAdaptor;
import org.overture.ast.analysis.QuestionAnswerAdaptor;
import org.overture.ast.analysis.intf.IAnalysis;
import org.overture.ast.analysis.intf.IAnswer;
import org.overture.ast.analysis.intf.IQuestion;
import org.overture.ast.analysis.intf.IQuestionAnswer;
Expand Down Expand Up @@ -415,4 +416,6 @@ public interface ITypeCheckerAssistantFactory extends IAstAssistantFactory
IQuestionAnswer<ILexLocation,Boolean> getIsEqVisitor();

IQuestion<TypeCheckInfo> getMultipleEqualityChecker();

IAnswer<String> getDetailedTypeDisplayer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1039,4 +1039,10 @@ public IQuestionAnswer<FreeVarInfo, LexNameSet> getFreeVariablesChecker()
}
return mulEqCheckr;
}

@Override
public IAnswer<String> getDetailedTypeDisplayer()
{
return new DetailedTypeDisplayer(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,17 @@ public String toDisplay(PType type)
}
}

public String toDetailedString(PType type)
{
try
{
return type.apply(af.getDetailedTypeDisplayer());
} catch (AnalysisException e)
{
return null;
}
}

public boolean isProduct(PType type, int size, String fromModule)
{
try
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* #%~
* The VDM Type Checker
* %%
* Copyright (C) 2008 - 2014 Overture
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #~%
*/
package org.overture.typechecker.utilities.type;

import org.overture.ast.analysis.AnalysisException;
import org.overture.ast.analysis.AnswerAdaptor;
import org.overture.ast.analysis.intf.IAnswer;
import org.overture.ast.node.INode;
import org.overture.ast.types.ARecordInvariantType;
import org.overture.ast.types.PType;
import org.overture.ast.util.Utils;
import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;

/**
* This class displays a detailed string representation of the Type.
*
* @author nbattle
*/
public class DetailedTypeDisplayer extends AnswerAdaptor<String>
{
protected ITypeCheckerAssistantFactory af;

public DetailedTypeDisplayer(ITypeCheckerAssistantFactory af)
{
this.af = af;
}

@Override
public String caseARecordInvariantType(ARecordInvariantType type)
throws AnalysisException
{
return "compose " + type.getName() + " of " + Utils.listToString(type.getFields()) + " end";
}

@Override
public String defaultPType(PType type) throws AnalysisException
{
IAnswer<String> displayer = af.getTypeDisplayer();
return type.apply(displayer);
}

@Override
public String createNewReturnValue(INode node) throws AnalysisException
{
return null;
}

@Override
public String createNewReturnValue(Object node) throws AnalysisException
{
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ public PType caseATypeImport(ATypeImport node, TypeCheckInfo question) throws An
checkKind(question.assistantFactory, expdef, istype, "type", node);
PType exptype = question.assistantFactory.createPTypeAssistant().typeResolve(expdef.getType(), null, THIS, question);

if (!question.assistantFactory.getTypeComparator().compatible(def.getType(), exptype))
// if (!question.assistantFactory.getTypeComparator().compatible(def.getType(), exptype))
String detail1 = question.assistantFactory.createPTypeAssistant().toDetailedString(def.getType());
String detail2 = question.assistantFactory.createPTypeAssistant().toDetailedString(exptype);

if (!detail1.equals(detail2))
{
TypeCheckerErrors.report(3192, "Type import of " + name
+ " does not match export from " + from.getName(), node.getLocation(), node);
TypeCheckerErrors.detail2("Import", def.getType().toString() // TODO: .toDetailedString()
, "Export", exptype.toString()); // TODO:
// .toDetailedString());
TypeCheckerErrors.detail2("Import", detail1, "Export", detail2);
}
}
}
Expand Down

0 comments on commit 03c6582

Please sign in to comment.