This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Confusing error message


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 15/04/11 18:24, Per Bothner wrote:
> Language#formatName is an instance method (not static), so it needs an
> appropriate Language instance.  But what is the appropriate Language
> if a situation where people might be mixing languages?  Is the current
> language a dynamic property, or does it depend on the language calling
> cdr?  The latter might be more correct, but for now I'd just use
> Language.getDefaultLanguage.

I understand now. I've made some changes to how types are discovered in
WrongType. I've attached a patch. Also included in the patch is the
addition of EmptyList which extends LList to provide an identity for the
empty list used for type lookup.

I added the empty list type to Scheme, along with an inexact type which
I noticed was missing.

Type checking seems to be a mixed bag in Kawa, most of the time the type
errors seem to emanate from a ClassCastException, which seems quite
elegant. I'll have to look into why cdr doesn't do it like this, but
when I find out why, would it be okay to try and make it use the
ClassCastException as well?

The black sheep however now has this behaviour,

#|kawa:1|# (cdr '())
Argument #1 '()' to 'cdr' has wrong type (empty-list)

and the currently not-yet-fixed ClassCastException ones (the majority)
pick up the EmptyList type,

#|kawa:3|# (cddr '())
Invalid parameter, was: gnu.lists.EmptyList cannot be cast to gnu.lists.Pair

so when I fix it to pick up language independent types, it'll read more
like the first example.

I was thinking about the expected types bit, it seems that such
information is hard-wired into the code, passed by the programmer
manually as strings, would it be feasible to make some sort of massive
hash mapping procedures to a list of their types? Allowing users to type
their own programs might get too hairy, but having a type hash for the
"core forms" might be quite useful internally. Then when you wanted to
inform the user of the expected type, you could index into the
procedures "type list" and pull it from there.

Thanks for reading,

Charles.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBAgAGBQJNqebUAAoJEG9M6fiX7bE4YfwIALCDEQDuMvNnvE2Bbw0rtszU
266zngWiBQntoqb+aGIiHMbOKyEgpKHoBgGlVK9eizBJix26yN1cACvMmZZKxZRd
ucePAMOK/X3ZuRd+XAc0ebt+KZlMCxo04EtduaYBLv/WSa/fJl/gJXWFeDv2RP/9
nUkmevyu6pbJUzfDn8thqRRu4zviymwVepPAeIVgGzalf4UhAJGLlXCPc2iOCvo5
hhAJfmnKyYq9sovfisRPjiCJj9nYRMnyXvRjsjhVdztkLwQEjliLlA9fJSMoOnxB
SPC2ERjzT4B/zGI9m3/gUNMxNo0WL8xeAgVY2HqkXvo3su/IJpMYwBSMfQ6BnSY=
=3xZn
-----END PGP SIGNATURE-----
Index: kawa/ChangeLog
===================================================================
--- kawa/ChangeLog      (revision 6960)
+++ kawa/ChangeLog      (working copy)
@@ -1,3 +1,8 @@
+2011-04-16  Charles Turner  <chturne@gmail.com>
+
+       * standard/Scheme.java (getTypeMap): Added the empty list type to
+       the hash
+
 2011-04-15  Per Bothner  <per@bothner.com>
 
        * standard/SchemeCompilation.java (checkDefaultBinding): Note that

Index: gnu/ChangeLog
===================================================================
--- gnu/ChangeLog       (revision 6960)
+++ gnu/ChangeLog       (working copy)
@@ -1,3 +1,13 @@
+2011-04-16  Charles Turner  <chturne@gmail.com>
+
+       * gnu/mapping/WrongType.java (getMessage): Retrieve types from the
+       currently default language.
+       * gnu/lists/LList.java: Give a class identity to the Empty field
+       for type information
+       * gnu/lists/EmptyList.java (new): New class that identifies empty
+       lists.
+       * gnu/lists/PairWithPosition.java: Corrected a comment
+
 2010-11-14  Per Bothner  <per@bothner.com>
 
        * q2/testsuite: New directory.
Index: gnu/mapping/WrongType.java
===================================================================
--- gnu/mapping/WrongType.java	(revision 6960)
+++ gnu/mapping/WrongType.java	(working copy)
@@ -3,6 +3,7 @@
 
 package gnu.mapping;
 import gnu.bytecode.Type;
+import gnu.expr.Language;
 
 /** Exception thrown when a procedure parameter has the wrong type. */
 
@@ -146,8 +147,11 @@
     return wex;
   }
 
+  @Override
   public String getMessage()
   {
+    // FIXME: Dynamically lookup the calling Language
+    Language currentLang = Language.getDefaultLanguage();
     StringBuffer sbuf = new StringBuffer(100);
     if (number == ARG_DESCRIPTION)
       {
@@ -168,7 +172,7 @@
       }
     if (argValue != null)
       {
-	sbuf.append(" (");
+	sbuf.append(" '");
 	String argString = argValue.toString();
 	if (argString.length() > 50)
 	  {
@@ -177,7 +181,7 @@
 	  }
 	else
 	  sbuf.append(argString);
-	sbuf.append(")");
+	sbuf.append("'");
       }
     if (procname != null && number != ARG_DESCRIPTION)
       {
@@ -188,8 +192,9 @@
     sbuf.append(" has wrong type");
     if (argValue != null)
       {
+       Type wrongType = Type.getType(argValue.getClass().getName());
 	sbuf.append(" (");
-	sbuf.append(argValue.getClass().getName());
+       sbuf.append(currentLang.formatType(wrongType));
 	sbuf.append(")");
       }
     Object expectType = expectedType;
Index: gnu/lists/LList.java
===================================================================
--- gnu/lists/LList.java	(revision 6960)
+++ gnu/lists/LList.java	(working copy)
@@ -25,7 +25,7 @@
   /** Do not use - only public for serialization! */
   public LList () { }
 
-  static public final LList Empty = new LList ();
+  static public final LList Empty = EmptyList.emptyList;
 
   /**
    * A safe function to count the length of a list.
Index: gnu/lists/EmptyList.java
===================================================================
--- gnu/lists/EmptyList.java	(revision 0)
+++ gnu/lists/EmptyList.java	(revision 0)
@@ -0,0 +1,20 @@
+package gnu.lists;
+
+/**
+ * This Singleton class represents an empty list, it's currently only used
+ * for type information in error messages.
+ *
+ * @author Charles Turner
+ * @since 16/04/2011
+ * @see gnu.lists.LList kawa.standard.Scheme
+ */
+
+public class EmptyList extends LList
+{
+  public static final EmptyList emptyList = new EmptyList ();
+  
+  private EmptyList()
+  {
+  }
+}
+
Index: gnu/lists/PairWithPosition.java
===================================================================
--- gnu/lists/PairWithPosition.java	(revision 6960)
+++ gnu/lists/PairWithPosition.java	(working copy)
@@ -8,7 +8,8 @@
   implements gnu.text.SourceLocator
 {
   String filename;
-  /** An encoding of lineNumber+(columnNumber<<20).
+  /** 
+   * An encoding of <code>(lineNumber << 12) + columnNumber</code>
    * Note if columnNumber is unspecified (0), then position is lineNumber. */
   int position;
 
@@ -17,6 +18,11 @@
     this.filename = filename;
   }
Index: kawa/standard/Scheme.java
===================================================================
--- kawa/standard/Scheme.java	(revision 6960)
+++ kawa/standard/Scheme.java	(working copy)
@@ -934,6 +934,7 @@
 	types.put ("real", LangObjType.realType);
 	types.put ("rational", LangObjType.rationalType);
 	types.put ("integer", LangObjType.integerType);
+       types.put ("inexact", LangObjType.dflonumType);
 	types.put ("symbol", ClassType.make("gnu.mapping.Symbol"));
 	types.put ("namespace", ClassType.make("gnu.mapping.Namespace"));
 	types.put ("keyword", ClassType.make("gnu.expr.Keyword"));
@@ -945,6 +946,7 @@
 	types.put ("character", ClassType.make("gnu.text.Char"));
 	types.put ("vector", LangObjType.vectorType);
 	types.put ("string", LangObjType.stringType);
+       types.put ("empty-list", ClassType.make("gnu.lists.EmptyList"));
 	types.put ("list", LangObjType.listType);
 	types.put ("function", ClassType.make("gnu.mapping.Procedure"));
 	types.put ("procedure", LangObjType.procedureType);

Attachment: types.patch.sig
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]