From ec1a0fc024f3270d1d9be755cc7a4dad35b73386 Mon Sep 17 00:00:00 2001 From: Martin Nilsson <nilsson@opera.com> Date: Sat, 16 Aug 2014 23:26:00 +0200 Subject: [PATCH] Make illegal casts throw exception. --- lib/master.pike.in | 12 +++---- lib/modules/ADT.pmod/Interval.pike | 11 +++--- lib/modules/ADT.pmod/Queue.pike | 2 +- .../ADT.pmod/Relation.pmod/Binary.pike | 2 +- lib/modules/ADT.pmod/Set.pike | 4 +-- lib/modules/ADT.pmod/Stack.pike | 4 +-- lib/modules/ADT.pmod/Struct.pike | 1 + lib/modules/ADT.pmod/Table.pmod | 3 +- lib/modules/Calendar.pmod/Event.pmod | 18 +++++----- lib/modules/GLUE.pmod/Events.pmod | 5 +-- lib/modules/Geography.pmod/Countries.pmod | 4 +-- lib/modules/Geography.pmod/Position.pike | 2 +- lib/modules/Int.pmod | 2 +- lib/modules/Locale.pmod/module.pmod | 2 +- lib/modules/MIME.pmod/ext_to_media_type.pmod | 1 + lib/modules/MIME.pmod/module.pmod | 6 ++-- lib/modules/Mapping.pmod | 2 +- lib/modules/NetUtils.pmod | 2 +- lib/modules/Parser.pmod/C.pmod | 1 + lib/modules/Parser.pmod/LR.pmod/module.pmod | 4 +-- lib/modules/Parser.pmod/XML.pmod/DOM.pmod | 35 +++++++++++++------ lib/modules/Parser.pmod/XML.pmod/Tree.pmod | 4 +-- .../Protocols.pmod/HTTP.pmod/Query.pike | 4 +-- .../Protocols.pmod/LysKOM.pmod/Raw.pike | 7 +++- lib/modules/Protocols.pmod/WebSocket.pmod | 11 +++--- lib/modules/Search.pmod/Utils.pmod | 4 +-- lib/modules/Sql.pmod/tds.pike | 4 ++- .../Standards.pmod/BSON.pmod/Binary.pike | 1 + .../Standards.pmod/BSON.pmod/Javascript.pike | 1 + .../Standards.pmod/BSON.pmod/ObjectId.pike | 3 +- .../Standards.pmod/BSON.pmod/Symbol.pike | 1 + .../Standards.pmod/BSON.pmod/module.pmod | 2 ++ lib/modules/Standards.pmod/URI.pike | 3 +- lib/modules/Standards.pmod/UUID.pmod | 3 +- lib/modules/Standards.pmod/X509.pmod | 2 +- lib/modules/Stdio.pmod/FakeFile.pike | 4 +-- lib/modules/String.pmod/HTML.pmod | 2 +- lib/modules/Tools.pmod/Hilfe.pmod | 2 +- 38 files changed, 104 insertions(+), 77 deletions(-) diff --git a/lib/master.pike.in b/lib/master.pike.in index d94b6d7ba5..aa5fc2f8da 100644 --- a/lib/master.pike.in +++ b/lib/master.pike.in @@ -5532,13 +5532,11 @@ class Version //! The version object can be casted into a string. protected mixed cast(string type) - { - switch(type) - { - case "string": - return sprintf("%d.%d",major,minor); - } - } + { + if( type=="string" ) + return sprintf("%d.%d",major,minor); + return UNDEFINED; + } } //! Version information about the current Pike version. diff --git a/lib/modules/ADT.pmod/Interval.pike b/lib/modules/ADT.pmod/Interval.pike index 76db53ce79..3bdf6e43df 100644 --- a/lib/modules/ADT.pmod/Interval.pike +++ b/lib/modules/ADT.pmod/Interval.pike @@ -246,9 +246,10 @@ int(0..1) contains(mixed x) { mixed beginning() { return start; } mixed end() { return stop; } -mixed cast(string type) { - switch (type) { - case "array": - return ({ start, stop }); - } +protected mixed cast(string type) { + switch (type) { + case "array": + return ({ start, stop }); + } + return UNDEFINED; } diff --git a/lib/modules/ADT.pmod/Queue.pike b/lib/modules/ADT.pmod/Queue.pike index 5bcbd3f584..fe5e8cb8a9 100644 --- a/lib/modules/ADT.pmod/Queue.pike +++ b/lib/modules/ADT.pmod/Queue.pike @@ -79,7 +79,7 @@ protected mixed cast(string to) { case "object": return this; case "array": return l+({}); } - error("Can not cast ADT.Queue to %s.\n", to); + return UNDEFINED; } protected string _sprintf(int t) { diff --git a/lib/modules/ADT.pmod/Relation.pmod/Binary.pike b/lib/modules/ADT.pmod/Relation.pmod/Binary.pike index f9967036ae..bb525b8237 100644 --- a/lib/modules/ADT.pmod/Relation.pmod/Binary.pike +++ b/lib/modules/ADT.pmod/Relation.pmod/Binary.pike @@ -314,6 +314,6 @@ mixed cast(string to) { case "mapping": return copy_value(val); default: - error("Can not cast ADT.Relation.Binary to %O.\n", to); + return UNDEFINED; } } diff --git a/lib/modules/ADT.pmod/Set.pike b/lib/modules/ADT.pmod/Set.pike index 4bf910458d..97eb408ef4 100644 --- a/lib/modules/ADT.pmod/Set.pike +++ b/lib/modules/ADT.pmod/Set.pike @@ -244,7 +244,7 @@ array(mixed) _values() //! An ADT.Set can be cast to an array or a multiset. -mixed cast(string to) +protected mixed cast(string to) { switch(to) { @@ -258,7 +258,7 @@ mixed cast(string to) return copy_value(set); default: - error("Cannot cast ADT.Set to %s.\n", to); + return UNDEFINED; } } diff --git a/lib/modules/ADT.pmod/Stack.pike b/lib/modules/ADT.pmod/Stack.pike index 28f0f927fb..4de3ce6c3f 100644 --- a/lib/modules/ADT.pmod/Stack.pike +++ b/lib/modules/ADT.pmod/Stack.pike @@ -141,12 +141,12 @@ this_program `+(this_program s) { return ns; } -mixed cast(string to) { +protected mixed cast(string to) { switch(to) { case "array": return _values(); default: - error("Cannot cast to %s.\n", to); + return UNDEFINED; } } diff --git a/lib/modules/ADT.pmod/Struct.pike b/lib/modules/ADT.pmod/Struct.pike index 6a478700a0..2ed01bfdb0 100644 --- a/lib/modules/ADT.pmod/Struct.pike +++ b/lib/modules/ADT.pmod/Struct.pike @@ -130,6 +130,7 @@ protected mixed cast(string to) { case "string": return encode(); case "array": return items->encode(); } + return UNDEFINED; } diff --git a/lib/modules/ADT.pmod/Table.pmod b/lib/modules/ADT.pmod/Table.pmod index 5f3fa5f3a0..f2494846f5 100644 --- a/lib/modules/ADT.pmod/Table.pmod +++ b/lib/modules/ADT.pmod/Table.pmod @@ -54,7 +54,7 @@ class table { return copy(m->table, m->fields, m->types); } - mixed cast(string type) + protected mixed cast(string type) { switch(type) { case "array": @@ -62,6 +62,7 @@ class table { case "string": return ASCII->encode(this); } + return UNDEFINED; } //! This method returns the column names for the table. The case used when diff --git a/lib/modules/Calendar.pmod/Event.pmod b/lib/modules/Calendar.pmod/Event.pmod index 62dcd6709b..baaef6e2dd 100644 --- a/lib/modules/Calendar.pmod/Event.pmod +++ b/lib/modules/Calendar.pmod/Event.pmod @@ -87,12 +87,11 @@ class Event return (t!='O')?0:sprintf("Event(%s:%O)",id,name); } - array(Event) cast(string to) + protected array(Event) cast(string to) { - if (to[..4]=="array") - return ({this}); - else - error("Can't cast to %O\n",to); + if (to[..4]=="array") + return ({this}); + return UNDEFINED; } //! Returns a description of the event. @@ -1404,12 +1403,11 @@ class SuperEvent return SuperEvent(res,flags&res,"?"); } - array(Event) cast(string to) + protected array(Event) cast(string to) { - if (to[..4]=="array") - return events; - else - error("Can't cast to %O\n",to); + if (to[..4]=="array") + return events; + return UNDEFINED; } protected string _sprintf(int t) diff --git a/lib/modules/GLUE.pmod/Events.pmod b/lib/modules/GLUE.pmod/Events.pmod index 58cfb363c2..5d9d597cb6 100644 --- a/lib/modules/GLUE.pmod/Events.pmod +++ b/lib/modules/GLUE.pmod/Events.pmod @@ -273,9 +273,10 @@ class Event return hash( sprintf( "%d %d %d", press, key, modifiers ) ); } - string cast(string to) { + protected string cast(string to) + { if(to=="string") return data; - error("Can not cast to %s.\n", to); + return UNDEFINED; } void update_modifiers(int _modifiers) { diff --git a/lib/modules/Geography.pmod/Countries.pmod b/lib/modules/Geography.pmod/Countries.pmod index a66b8d14b5..cc8494f5dd 100644 --- a/lib/modules/Geography.pmod/Countries.pmod +++ b/lib/modules/Geography.pmod/Countries.pmod @@ -376,10 +376,10 @@ class Country //! It is possible to cast a country to a string, //! which will be the same as performing //! @expr{country->name;@}. - string cast(string to) + protected string cast(string to) { if (to[..5]=="string") return name; - error("can't cast to %O\n",to); + return UNDEFINED; } string _sprintf(int t) diff --git a/lib/modules/Geography.pmod/Position.pike b/lib/modules/Geography.pmod/Position.pike index 29950c094a..9c0d5f08af 100644 --- a/lib/modules/Geography.pmod/Position.pike +++ b/lib/modules/Geography.pmod/Position.pike @@ -576,7 +576,7 @@ protected string|array cast(string to) if (to[..5]=="string") return latitude()+" "+longitude(); - error("can't cast to %O\n",to); + return UNDEFINED; } //! diff --git a/lib/modules/Int.pmod b/lib/modules/Int.pmod index 5bfa4a7773..484aa3669a 100644 --- a/lib/modules/Int.pmod +++ b/lib/modules/Int.pmod @@ -162,7 +162,7 @@ class Inf { case "float": return Math.inf; default: - error("Can not cast to %O.\n", to); + return UNDEFINED; } } protected string _sprintf(int t) { diff --git a/lib/modules/Locale.pmod/module.pmod b/lib/modules/Locale.pmod/module.pmod index 4495f028f7..5392de336e 100644 --- a/lib/modules/Locale.pmod/module.pmod +++ b/lib/modules/Locale.pmod/module.pmod @@ -564,7 +564,7 @@ class DeferredLocale( protected string project, { if(to=="string") return lookup(); if(to=="mixed" || to=="object") return this; - error( "Cannot cast DeferredLocale to "+to+".\n" ); + return UNDEFINED; } protected int _is_type(string type) { diff --git a/lib/modules/MIME.pmod/ext_to_media_type.pmod b/lib/modules/MIME.pmod/ext_to_media_type.pmod index 7b54884bbb..bbdc3462d6 100644 --- a/lib/modules/MIME.pmod/ext_to_media_type.pmod +++ b/lib/modules/MIME.pmod/ext_to_media_type.pmod @@ -1661,4 +1661,5 @@ string `()(string ext) { protected mixed cast(string to) { if(to=="mapping") return small_ext2type + ext2type; + return UNDEFINED; } diff --git a/lib/modules/MIME.pmod/module.pmod b/lib/modules/MIME.pmod/module.pmod index 0693f0623d..ec3a986383 100644 --- a/lib/modules/MIME.pmod/module.pmod +++ b/lib/modules/MIME.pmod/module.pmod @@ -141,7 +141,7 @@ protected class StringRange case "object": return this_object(); default: - error("StringRange: Unsupported cast to %s.\n", type); + return UNDEFINED; } } protected int _search(string frag, int|void pos) @@ -1190,13 +1190,13 @@ class Message { //! //! @seealso //! @[create()] - string cast( string dest_type ) + protected string cast( string dest_type ) { string data; object body_part; if (dest_type != "string") - error( "Can't cast Message to %s.\n", dest_type); + return UNDEFINED; data = getencoded( ); diff --git a/lib/modules/Mapping.pmod b/lib/modules/Mapping.pmod index 60a25367c5..a34ebcbde0 100644 --- a/lib/modules/Mapping.pmod +++ b/lib/modules/Mapping.pmod @@ -169,7 +169,7 @@ class ShadowedMapping(protected mapping|ShadowedMapping parent) case "mapping": return joined + ([]); case "array": return (array)joined; } - return joined + ([]); + return UNDEFINED; } protected mixed _search(mixed val) diff --git a/lib/modules/NetUtils.pmod b/lib/modules/NetUtils.pmod index 0aac99ed5b..8ff63a039b 100644 --- a/lib/modules/NetUtils.pmod +++ b/lib/modules/NetUtils.pmod @@ -260,7 +260,7 @@ class NetMask case "array": return ({ net, mask }); default: - error("Can not cast to %O\n", type ); + return UNDEFINED; } } diff --git a/lib/modules/Parser.pmod/C.pmod b/lib/modules/Parser.pmod/C.pmod index d09792bfc1..a2a1c7267e 100644 --- a/lib/modules/Parser.pmod/C.pmod +++ b/lib/modules/Parser.pmod/C.pmod @@ -137,6 +137,7 @@ class Token protected mixed cast(string to) { if(to=="string") return text; + return UNDEFINED; } //! Characters and ranges may be indexed from the text contents of the token. diff --git a/lib/modules/Parser.pmod/LR.pmod/module.pmod b/lib/modules/Parser.pmod/LR.pmod/module.pmod index 1afc9158b6..a9157e9793 100644 --- a/lib/modules/Parser.pmod/LR.pmod/module.pmod +++ b/lib/modules/Parser.pmod/LR.pmod/module.pmod @@ -629,11 +629,11 @@ class Parser //! //! @param type //! Type to cast to. - mixed cast(string type) + protected mixed cast(string type) { if (type == "string") return _sprintf(); - error("Cast to %s not supported\n", type); + return UNDEFINED; } /* Here come the functions that actually do some work */ diff --git a/lib/modules/Parser.pmod/XML.pmod/DOM.pmod b/lib/modules/Parser.pmod/XML.pmod/DOM.pmod index 0be1615297..b9eee78e7f 100644 --- a/lib/modules/Parser.pmod/XML.pmod/DOM.pmod +++ b/lib/modules/Parser.pmod/XML.pmod/DOM.pmod @@ -94,8 +94,11 @@ class NodeList } protected Node `[](int index) { return item(index); } protected int _sizeof() { return get_length(); } - protected array(Node) cast(string to) { - return to[..4] == "array" && values(this); + protected array(Node) cast(string to) + { + if(to[..4] == "array") + return values(this); + return UNDEFINED; } Node item(int index) @@ -160,8 +163,11 @@ class NamedNodeMap } protected int _sizeof() { return get_length(); } - protected mapping(string:Node) cast(string to) { - return to[..6] == "mapping" && copy_value(map); + protected mapping(string:Node) cast(string to) + { + if(to[..6] == "mapping") + return copy_value(map); + return UNDEFINED; } Node item(int index) @@ -542,7 +548,12 @@ class CharacterData substring_data(offset+count, get_length())); } - string cast(string to) { return to == "string" && get_data(); } + protected string cast(string to) + { + if(to == "string") + return get_data(); + return UNDEFINED; + } } class Attr @@ -873,9 +884,11 @@ class Entity string get_notation_name() { return notation_name; } protected int is_readonly() { return name != 0; } - string cast(string to) + protected string cast(string to) { - return to == "string" && ((array(string))get_child_nodes())*""; + if(to == "string") + return ((array(string))get_child_nodes())*""; + return UNDEFINED; } protected int child_is_allowed(Node child) @@ -913,11 +926,11 @@ class EntityReference return owner_document->create_entity_reference(name); } - string cast(string to) + protected string cast(string to) { - return to == "string" && - (entity? (string)entity : - "&"+name+";"); + if(to == "string") + return (entity? (string)entity : "&"+name+";"); + return UNDEFINED; } NodeList get_child_nodes() { return entity && entity->get_child_nodes(); } diff --git a/lib/modules/Parser.pmod/XML.pmod/Tree.pmod b/lib/modules/Parser.pmod/XML.pmod/Tree.pmod index 31fc02f6b4..d5fed645fd 100644 --- a/lib/modules/Parser.pmod/XML.pmod/Tree.pmod +++ b/lib/modules/Parser.pmod/XML.pmod/Tree.pmod @@ -1027,10 +1027,10 @@ protected class VirtualNode { //! It is possible to cast a node to a string, which will return //! @[render_xml()] for that node. - mixed cast(string to) { + protected mixed cast(string to) { if(to=="object") return this; if(to=="string") return render_xml(); - error( "Can not case Node to "+to+".\n" ); + return UNDEFINED; } // FIXME: Consider moving this to the corresponding base node classes? diff --git a/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike b/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike index b6976365e7..2eafd390bc 100644 --- a/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike +++ b/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike @@ -1063,7 +1063,7 @@ int total_bytes() //! @decl string cast("string") //! Gives back the answer as a string. -array|mapping|string cast(string to) +protected array|mapping|string cast(string to) { switch (to) { @@ -1079,7 +1079,7 @@ array|mapping|string cast(string to) data(); return buf; } - error("HTTP.Query: can't cast to "+to+"\n"); + return UNDEFINED; } //! Minimal simulation of a @[Stdio.File] object. diff --git a/lib/modules/Protocols.pmod/LysKOM.pmod/Raw.pike b/lib/modules/Protocols.pmod/LysKOM.pmod/Raw.pike index 12c8cc157c..03327e1195 100644 --- a/lib/modules/Protocols.pmod/LysKOM.pmod/Raw.pike +++ b/lib/modules/Protocols.pmod/LysKOM.pmod/Raw.pike @@ -70,7 +70,12 @@ class Send request=r; callback=c; } - int cast(string i) { return ref; } + protected int cast(string type) + { + if( type=="int" ) + return ref; + return UNDEFINED; + } void write() { out_req++; diff --git a/lib/modules/Protocols.pmod/WebSocket.pmod b/lib/modules/Protocols.pmod/WebSocket.pmod index 2cb5f00447..e44c4d6936 100644 --- a/lib/modules/Protocols.pmod/WebSocket.pmod +++ b/lib/modules/Protocols.pmod/WebSocket.pmod @@ -231,12 +231,11 @@ class Frame { return b->get(); } - protected string cast(string to) { - if (to == "string") { - return encode(); - } - - error("Cannot cast %O to %O\n", this, to); + protected string cast(string to) + { + if (to == "string") + return encode(); + return UNDEFINED; } } diff --git a/lib/modules/Search.pmod/Utils.pmod b/lib/modules/Search.pmod/Utils.pmod index 72622fa7d0..07691e2ad5 100644 --- a/lib/modules/Search.pmod/Utils.pmod +++ b/lib/modules/Search.pmod/Utils.pmod @@ -147,13 +147,13 @@ class ProfileEntry { return this_object(); } - mixed cast(string to) { + protected mixed cast(string to) { switch(to) { case "object": return this_object(); case "array": return indices(vals); case "multiset": return (multiset)indices(vals); default: - error("Can not cast ADTSet to "+to+".\n"); + return UNDEFINED; } } } diff --git a/lib/modules/Sql.pmod/tds.pike b/lib/modules/Sql.pmod/tds.pike index a2b180e47e..5b1d584b8f 100644 --- a/lib/modules/Sql.pmod/tds.pike +++ b/lib/modules/Sql.pmod/tds.pike @@ -420,8 +420,10 @@ protected { strings += ({ raw }); } - mixed cast(string s) + protected string cast(string type) { + if( type!="string" ) return UNDEFINED; + int trailer_start = flags && 4; foreach(segments, string|int seg) { trailer_start += stringp(seg)?sizeof(seg):(seg<0)?8:4; diff --git a/lib/modules/Standards.pmod/BSON.pmod/Binary.pike b/lib/modules/Standards.pmod/BSON.pmod/Binary.pike index 419246e13f..6147de1b95 100644 --- a/lib/modules/Standards.pmod/BSON.pmod/Binary.pike +++ b/lib/modules/Standards.pmod/BSON.pmod/Binary.pike @@ -46,5 +46,6 @@ return sprintf("%-4H", data); else return data; } + return UNDEFINED; } diff --git a/lib/modules/Standards.pmod/BSON.pmod/Javascript.pike b/lib/modules/Standards.pmod/BSON.pmod/Javascript.pike index e2bfaf68f0..9d3ffad7b3 100644 --- a/lib/modules/Standards.pmod/BSON.pmod/Javascript.pike +++ b/lib/modules/Standards.pmod/BSON.pmod/Javascript.pike @@ -19,5 +19,6 @@ { if(type == "string") return data; + return UNDEFINED; } diff --git a/lib/modules/Standards.pmod/BSON.pmod/ObjectId.pike b/lib/modules/Standards.pmod/BSON.pmod/ObjectId.pike index c3817bc3b4..a47a42e372 100644 --- a/lib/modules/Standards.pmod/BSON.pmod/ObjectId.pike +++ b/lib/modules/Standards.pmod/BSON.pmod/ObjectId.pike @@ -59,6 +59,5 @@ protected mixed cast(string t) { if(t == "string") return String.string2hex(get_id()); - else - throw(Error.Generic("invalid cast of ObjectId to " + t + "\n")); + return UNDEFINED; } diff --git a/lib/modules/Standards.pmod/BSON.pmod/Symbol.pike b/lib/modules/Standards.pmod/BSON.pmod/Symbol.pike index 462a34ce66..9e2964c9cd 100644 --- a/lib/modules/Standards.pmod/BSON.pmod/Symbol.pike +++ b/lib/modules/Standards.pmod/BSON.pmod/Symbol.pike @@ -19,5 +19,6 @@ { if(type == "string") return data; + return UNDEFINED; } diff --git a/lib/modules/Standards.pmod/BSON.pmod/module.pmod b/lib/modules/Standards.pmod/BSON.pmod/module.pmod index 39d7c434f6..490bbbc563 100644 --- a/lib/modules/Standards.pmod/BSON.pmod/module.pmod +++ b/lib/modules/Standards.pmod/BSON.pmod/module.pmod @@ -382,6 +382,7 @@ object MinKey = class { if(type == "string") return "MinKey"; + return UNDEFINED; } }(); @@ -395,6 +396,7 @@ object MaxKey = class { if(type == "string") return "MinKey"; + return UNDEFINED; } }(); diff --git a/lib/modules/Standards.pmod/URI.pike b/lib/modules/Standards.pmod/URI.pike index e7fdf1b2a8..b67e714668 100644 --- a/lib/modules/Standards.pmod/URI.pike +++ b/lib/modules/Standards.pmod/URI.pike @@ -452,7 +452,7 @@ mixed `[]=(string property, mixed value) //! When cast to mapping, return a mapping with scheme, authority, //! user, password, host, port, path, query, fragment, raw_uri, //! base_uri as documented above. -string|mapping cast(string to) +protected string|mapping cast(string to) { switch(to) { @@ -465,6 +465,7 @@ string|mapping cast(string to) "raw_uri", "base_uri", }); return mkmapping(i, rows(this, i)); } + return UNDEFINED; } //! Returns path and query part of the URI if present. diff --git a/lib/modules/Standards.pmod/UUID.pmod b/lib/modules/Standards.pmod/UUID.pmod index 8a0905dd35..692f25d2cb 100644 --- a/lib/modules/Standards.pmod/UUID.pmod +++ b/lib/modules/Standards.pmod/UUID.pmod @@ -231,7 +231,7 @@ class UUID { validate(); } - mixed cast(string to) { + protected mixed cast(string to) { switch(to) { case "string": return str(); case "mapping": return ([ @@ -240,6 +240,7 @@ class UUID { "time_hi_and_version" : time_hi_and_version(), ]); } + return UNDEFINED; } } diff --git a/lib/modules/Standards.pmod/X509.pmod b/lib/modules/Standards.pmod/X509.pmod index 6add1cd27d..4ff17f2c12 100644 --- a/lib/modules/Standards.pmod/X509.pmod +++ b/lib/modules/Standards.pmod/X509.pmod @@ -706,7 +706,7 @@ class TBSCertificate ]); break; default: - error("Can't case %O to %O\n", this_program, to); + return UNDEFINED; break; } } diff --git a/lib/modules/Stdio.pmod/FakeFile.pike b/lib/modules/Stdio.pmod/FakeFile.pike index 744ac4b918..ac676a12a1 100644 --- a/lib/modules/Stdio.pmod/FakeFile.pike +++ b/lib/modules/Stdio.pmod/FakeFile.pike @@ -319,12 +319,12 @@ string _sprintf(int t) { // FakeFile specials. //! A FakeFile can be casted to a string. -mixed cast(string to) { +protected mixed cast(string to) { switch(to) { case "string": return data; case "object": return this; } - error("Can not cast object to %O.\n", to); + return UNDEFINED; } //! Sizeof on a FakeFile returns the size of its contents. diff --git a/lib/modules/String.pmod/HTML.pmod b/lib/modules/String.pmod/HTML.pmod index 96ca459d4f..4cfdb3439d 100644 --- a/lib/modules/String.pmod/HTML.pmod +++ b/lib/modules/String.pmod/HTML.pmod @@ -259,6 +259,6 @@ class OBox { return rows; if(to=="string") return render(); - error("Could not cast OBox object to %s.\n", to); + return UNDEFINED; } } diff --git a/lib/modules/Tools.pmod/Hilfe.pmod b/lib/modules/Tools.pmod/Hilfe.pmod index 6b7de25cac..4aff71cfb1 100644 --- a/lib/modules/Tools.pmod/Hilfe.pmod +++ b/lib/modules/Tools.pmod/Hilfe.pmod @@ -1153,7 +1153,7 @@ class Expression { case "array": return tokens; case "string": return code(); } - error("Can not cast to %O\n", to); + return UNDEFINED; } protected string _sprintf(int t) { -- GitLab